Java method call overloading logic

java, jvm, overloading

Solution

Overloading is determined statically by the compiler. Overriding is done at execution time, but that isn't a factor here.

The static type of `a` is A, so the first method call is resolved to `call(A a)`.

Problem

For the following code why does it print A, B? I would expect it to print B, B. Also, does the method call performed by the JVM is evaluated dynamically or statically? ``` 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); } } ```

Original source