First of all, You should keep in mind that there is no compile-time memory allocation. The question conflates compile-time with static binding and run-time with dynamic binding.
** Static binding happens at compile time; dynamic binding happens at runtime.
Let´s consider an example:
class myclass {
void here() {
System.out.println("Here from myclass !!");
}
void here(int i) {
System.out.println("Here !!" + i);
}
}
class thisclass extends myclass {
void here() {
System.out.println("Here from thisclass !!");
}
}
public class poly {
public static void main(String s[]) {
myclass m= new myclass();
myclass a= new thisclass();
m.here();
m.here(12);
a.here();
a.here(13);
}
}
Now, when you write:
myclass m= new thisclass();
m.here(18);
what happens at compile-time is the resolution of method signature: you are calling here(int) and that choice is final. This is termed "static binding".
What happens at runtime is method dispatch: the runtime chooses a here(int) implementation appropriate to the runtime type of the object referenced by m.
There are two methods to choose from: myclass.m(int) and thisclass.m(int), and the runtime chooses the latter in this particular example. This is termed "dynamic binding".
The Java Language Specification prescribes the rules on choosing the correct method to invoke at runtime. These rules imply a procedure known as "dynamic binding" for the general case. But if you are asking whether any specific process always happens at runtime, that is totally different: an optimizing JIT compiler can see that there is only one method to choose from and output a direct call instruction with a fixed function address.
4