在类和方法之间使用"final"关键字时我有很大的困惑因为最终方法只支持继承但不支持最终类
final class A{
void print(){System.out.println("hello world");}
}
class Final extends A{
public static void main(String[] args){
System.out.println("hello world");
}
}
Run Code Online (Sandbox Code Playgroud)
错误:
不能从最后的A级继承最终的延伸A {最终方法是......
class Bike{
final void run(){System.out.println("run");}
}
class Honda extends Bike{
public static void main(String[] args){
Honda h=new Honda();
h.run();
}
}
Run Code Online (Sandbox Code Playgroud)