For the following code:
class A {
public void ex(Object o) {
System.out.println("A");
}
}
class B extends A {
public void ex(B o) {
System.out.println("B");
}
}
class C extends B {
public void ex(A o) {
System.out.println("C");
}
}
public class Main {
public static void main(String argv[]) {
C xx;
xx = new C();
xx.ex(xx); // This prints B
}
}
Why is the result of calling the ex method "B"? Both the reference and class type are C, still the method executed is the one from the superclass.