Java Reference
In-Depth Information
Program counter. The program counter is the number of the next state-
ment of the method body to execute. Initially, it is 1, and it is increment-
ed each time a statement is executed.
Scope box. The scope box is used to find a variable or method that is ref-
erenced in the method body. Its value depends on what kind of method
this is:
for a static method : The name of the class in which the
method is defined.
for an instance method : The name of the object in which
the method resides.
for a constructor : The name of the object that was just created.
Parameters. Each parameter of the method appears as a variable.
Parameters are drawn in the lower left of the frame for reasons that will
become clear later.
Local variables. Each local variable of the method appears in the frame.
As an example, consider this class:
public class C {
public void meth( int p) {
double d;
}
}
Suppose we execute these statements:
C c= new C();
c.meth(5);
Execution of the first statement creates a new folder, stores its name in vari-
able c , and calls procedure c.meth . Figure 2.9 shows variable c , the folder, and
the frame for the method call c.meth just after the frame is created and the argu-
ment is stored in the parameter.
The call stack: the stack of frames for uncompleted method calls
A frame for a method call lasts as long as the method call is being executed.
When the call is finished, the frame is erased. If the method is called again later,
a new frame is created for it.
a1
meth : 1
a1
C
c
a1
y
p
5
d
meth( int )
Figure 2.9:
The frame just after the argument has been assigned to parameter p
Search WWH ::




Custom Search