For the following code, why does it print A, B? I expect it to print B, B. Also, is the JVM method call dynamically or statically evaluated?
public class Main {
class A {
}
class B extends A {
}
public void call(A a) {
System.out.println("I'm A");
}
public void call(B a) {
System.out.println("I'm B");
}
public static void main(String[] args) {
Main m = new Main();
m.runTest();
}
void runTest() {
A a = new B();
B b = new B();
call(a);
call(b);
}
}
source
share