一、实现Java多态性的时候,关于方法调用的优先级
我们这样假设下,super(父类)、this(当前类对象)、show(方法)、object(对象),方法调用优先顺序:
- ①this.show(object)>②super.show(object)> ③this.show((super)object)>④super.show((super)object)
- 文字描述:
①当前类方法(当前类对象)> ② 父类方法(当前类对象)> ③当前类方法(父类对象)> ④父类方法(父类对象)
案例
class A {
public String show(D obj) {
return ("A and D");
}
public String show(A obj) {
return ("A and A");
}
}
class B extends A{
public String show(B obj){
return ("B and B");
}
public String show