I thought that the output of the following code would have been ABB, instead it is AAB, why does java do static binding here?
public class A {}
public class B extends A {}
public class C {
void f(A x) {
System.out.println("A");
}
void f(B x) {
System.out.println("B");
}
public static void main(String[] args) {
C c = new C();
A a1 = new A();
A a2 = new B();
B a3 = new B();
c.f(a1);
c.f(a2);
c.f(a3);
}
}
Sorry for the mistakes I might have done, it's my first question.