//关键字 Final 测试 public class Final { public static void main(String[] args) { Animal n=new Animal();//被final修饰的类还可以创建对象 // n.A=8989;报错:无法为最终变量“a”赋值 System.out.println(n.A);//100 } } final class Animal{ final int A=100; public void eat(){ System.out.println("小动物们又开始吃晚饭啦~"); } } //class Cat extends Animal{}Cannot inherit from final 'cn.tedu.review.Animal' //被final修饰的类不能继承 class Fruit{ final int A=100;//常量定义的时候必须赋值,且常量的名称必须是全大写 public final void grow(){ System.out.println("长成又大有甜的果实啦~"); } } class banana extends Fruit{ // public void grow(){}报错:grow()' cannot override 'grow()' in 'cn.tedu.review.Fruit'; overridden method is final //被final修饰的方法不能被重写 }