HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
1. Feel Free to ask and submit anything on and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.

corejava-inheritance: Is memory allocation done in static binding in java?

If memory is allocated to variable at compile time. So If we do not executed that program, What would be happen with that memory?

corejava x 353
inheritance x 7
Posted On : 2014-07-15 01:07:02.0
profile Garima Gupta - Garima Gupta


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();;;;;

Now, when you write:
myclass m= new thisclass();;

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.

Posted On : 2014-07-15 01:21:09
Satisfied : 1 Yes  0 No
profile Saksham Kumar - Saksham Kumar
Reply This Thread

Post Answer
Please Login First to Post Answer: Login login with facebook -