final关键字:
*修饰变量:
——常量
*修饰方法:
——改方法不可被子类重写。但是可以被重载!
*修饰类:
——修饰的类不能有子类,不能被继承。
比如:Math、String。
列子:
final int a =22//常量,不能再赋值
public static final void test(){ }//修饰方法,不能在子类中重写,但是可以被子类重载
final class animal { }//修饰类,修饰的类是最终的类,没有子类,也不能被继承
*修饰变量:
——常量
*修饰方法:
——改方法不可被子类重写。但是可以被重载!
*修饰类:
——修饰的类不能有子类,不能被继承。
比如:Math、String。
列子:
final int a =22//常量,不能再赋值
public static final void test(){ }//修饰方法,不能在子类中重写,但是可以被子类重载
final class animal { }//修饰类,修饰的类是最终的类,没有子类,也不能被继承