class WithFinal{
private final void f(){
System.out.println("WithFinal.f()");
}
private void g(){
System.out.println("WithFinal.g()");
}
}
class OverridingPrivate extends WithFinal{
private final void f(){
System.out.println("OverridingPrivate.f()");
}
private void g(){
System.out.println("OverridingPrivate.g()");
}
}
class OverridingPrivate2 extends OverridingPrivate{
public final void f(){
System.out.println("OverridingPrivate2.f()");
}
public void g(){
System.out.println("OverridingPrivate2.g()");
}
}
public class FinalOverriding {
public static void main(String[] args) {
OverridingPrivate2 op2 = new OverridingPrivate2();
op2.f();
op2.g();
OverridingPrivate op = op2;
op.f();//编译报错
op.g();//编译报错
WithFinal wf = op2;
wf.f();//编译报错
wf.g();//编译报错
}
}
为什么???