有如下代码:
public static void main(String[] args) {
A a2 = new B();
B b = new B();
C c = new C();
D d = new D();
System.out.println(" 1:"+a2.show(b));
System.out.println(" 2:"+a2.show(c));
System.out.println(" 3:"+a2.show(d));
System.out.println(" 4:"+b.show(c));
System.out.println(" 5:"+b.show(d));
}
static class A {
public String show(D obj){
return ("A and D");
}
public String show(A obj){
return ("A and A");
}
}
static class B extends A{
public String show(B obj){
return ("B and B");
}
public String show(A obj){
return ("B and A");
}
}
static class C extends B{}
static class D extends B{}
运行后结果是:
1:B and A
2:B and A
3:A and D
4:B and B
5:A and D
小弟非常不理解这样的输入结果,望各位大神指教