Possible duplicate:
Java Instantiation.
Suppose we have a Java class test, this class has two data fields a and b and has a foo () method. When we run "Test t = new Test ()", I want to know the following.
- what happened on the stack?
- What happened to the bunch?
- We have one copy of the class and many instances (objects) at runtime, right? So where is the contents of the class stored? The content of the class is static.
- On the heap, I think that the data fields a and b should be stored as they are dynamic (specific to a specific object). What about the foo () method? Do I need to store the contents of foo () along with a and b on the heap?
Basically, I want to know the magic of a new keyword?
source share