实现Java多态性的时候,关于方法调用的优先级:
我们这样假设下,super(超类)、this(当前类对象)、show(方法)、object(对象),方法调用优先顺序: ①this.show(object)>②super.show(object)> ③this.show((super)object)>④super.show((super)object)
先看以下代码
class ParentCls {
public String show(ChildA obj){
return "Parent and ChildA";
}
public String show(ParentCls obj) {
return "Parent";
}
}
然后写一个子类ChildA ,继承ParentCls :
class ChildA extends ParentCls{
public String show(ChildA obj) {
return "ChildA";
};
public String show(ParentCls obj) {
return "ChildA and Parent";
};
}
写一个子类Chi