- 修饰变量:常量
- 修饰方法:该方法不可被子类重写(override),但是可以被重载(overload)!!!!!
- 修饰类:修饰的类不能有子类,不能被继承。比如:Math、String。
package theChildOfGod.bjxy.testFinal;
public /*final*/class Animal{ //final修饰类,说明这个类不能被继承!
String eye;
public /*final*/ void run() { //final加到方法之前,意味着该方法不可以被重写
System.out.println("跑跑!");
}
}
class Bird extends Animal{
public void run(){
super.run();
System.out.println("我是一只小小鸟!飞呀飞不高!");
}
}
package theChildOfGod.bjxy.testFinal;
public class TestFinal {
public static void main(String[] args) {
final int MAX_VALUE = 20; //常量
}
}