public class Test {
public class Car {
final void move() {
System.out.println("Car is moving");
}
}
public class BMW extends Car {
void goHome() {
move();
System.out.println("Car is go home");
}
}
public static void main(String[] args) {
Test test=new Test();
BMW car = test.new BMW();
car.goHome();
}
}
本文通过一个具体的Java程序示例,展示了如何使用final关键字来定义不可被子类重写的方法,并且演示了如何在一个子类中调用父类的final方法。

被折叠的 条评论
为什么被折叠?



