Whenever a program runs in JVM, different ways the memory is managed is depicted in the figure below.
Now coming back to the earlier question, so whenever a methos is executed, it creates a new data record on Stack. So each instance of method call has a exclusive data record associated with it. (Figure 2) . And when a method calls other methods, records of the called methods are stacked up along with the caller. (Figure 3).
This explains or answers for the below, as static methods would be no different from non-static methods, but there is a catch here. This statement is correct only if the arguments are primitives, but when they are objects, the objects would still reside on Heap and are referred from within the stack. (Figure 4)
Note: figures displayed are extracted from book (in Google Book Search) - SCJP Exam for J2SE 5 by Paul Sanghera and from lecture slides of Gerald Weber.
that was realy informative i was just brushing with ooad
ReplyDeletethanks