package test;
public class Test1{
public static void main(String arg[]){
A a1 = new A();
A a2 = new B();
B b = new B();
C c = new C();
D d = new D();
System.out.println(a1.show(b));
System.out.println(a1.show(c));
System.out.println(a1.show(d));
System.out.println(a2.show(b));
System.out.println(a2.show(c));
System.out.println(a2.show(d)); //A-D
System.out.println(b.show(b));
System.out.println(b.show(c));
System.out.println(b.show(d));
}
}
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(A obj){
return ("B and A");
}
public String show(B obj){
return ("B and B");
}
}
class C extends B{
public String show(C obj){
return ("C and C");
}
public String show(B obj){
return ("B and C");
}
}
class D extends B{
public String show(D obj){
return ("D and D");
}
public String show(B obj){
return ("B and D");
}
}
A and A
A and A
A and D
B and A
B and A
A and D
B and B
B and B
A and D
为什么第4个输出不是B and B而是 B and A明明入参就是B类啊,现实让我懵逼。求解答