The following example is from Dan's mock exam.
What's the output of following code:
class A {
void m1(A a) {System.out.print("A");}
}
class B extends A {
void m1(B b) {System.out.print("B");}
}
class C extends B {
void m1(C c) {System.out.print("C");}
}
class D {
public static void main(
String[] args) {
A a1 = new A();
B b1 = new B();
C c1 = new C();
A c2 = new C();
c2.m1(a1);
c2.m1(b1);
c2.m1(c1);
}
}
The answer is AAA. I don't understand it. Isn't at runtime c2 will be bound to type C and thus the result should be ABC? Please help me.
Thanks.