写出以下代码的输出结果
class A{
public String f(D obj){return ("A and D");}
public String f(A obj){return ("A and A");}
}
class B extends A{
public String f(B obj){return ("B and B");}
public String f(A obj){return ("B and A");}
}
class C extends B{}
class D extends B{}
class test{
A a1 = new A();
A a2 = new B();
B b = new B();
C c = new C();
D d = new D();
System.out.println(a1.f(b)); A and A
System.out.println(a1.f(c)); A and A
System.out.println(a1.f(d)); A and D
System.out.println(a2.f(b)); B and A
System.out.println(a2.f(c)); B and A
System.out.println(a2.f(d)); A and D
System.out.println(b.f(b)); B and B
System.out.println(b.f(c)); B and B
System.out.println(b.f(d)); A and D
}