Java Reference
In-Depth Information
objects. Three strings are pushed onto the names stack, and two ints are pushed onto
grades . Then names and grades are passed into modifyStacks . The parameter one points
to the stack of Strings and two points to the stack of grades , as Figure 1.13 shows.
FIGURE 1.13 The references from main are copied into the parameters of
modifyStacks .
“Jane”
“Edward”
“Kim”
names
one
grades
two
87
95
The memory of the
call stack for main
Heap
The memory of the
call stack for modifyStacks
Pushing 50 onto two is the same as pushing it onto grades because the two references
point to the same stack. Similarly, popping a value off one removes “Jane” from the names
stack.
Note that setting one equal to a new Stack does not affect the Stack that names points
to. We cannot modify the reference names within modifyStacks . Figure 1.14 shows the
references and objects just before the modifyStacks method returns.
FIGURE 1.14 Assigning the one reference to a new Stack does not affect the names
stack.
names
one
“Edward”
“Kim”
grades
two
50
87
95
The memory of the
call stack for main
Heap
The memory of the
call stack for modifyStacks
 
Search WWH ::




Custom Search