I want to know why the third output is NOT b.
Here is my code:
public class SimpleTests {
public void func(A a) {
System.out.println("Hi A");
}
public void func(B b) {
System.out.println("Hi B");
}
public static void main(String[] args) {
A a = new A();
B b = new B();
A c = new B();
SimpleTests i = new SimpleTests();
i.func(a);
i.func(b);
i.func(c);
}
}
class A {}
class B extends A {}
And here is the output:
Hi A
Hi B
Hi A
Could someone tell me why the 3rd output is Hi A
, NOT Hi B
. as the real c is a instance of B.