其实在继承链中对象方法的调用存在一个优先级:this.show(O)、super.show(O)、this.show((super)O)、super.show((super)O)。
/**
* Created by Keben on 2018-10-08.
*/
public class A {
protected String get(A a){return "A - A";}
// protected String get(C c){return "A - C";}
}
class B extends A{
@Override
protected String get(A a){return "B - A";}
}
class C extends B{
}
class Main{
public static void main(String[] args) {
A b = new B();
C c = new C();
System.out.println(b.get(c));
}
}
网友评论