When you pass an object
as an argument, remember that the argument and the parameter are not
the same variable. Instead, there are two variables (one in the caller
and one in the callee) that have the same value, at least initially.
For example we can draw a stack diagram for the last
call in our last example:
In this case, the variable values are the same. However if
happened to change one of the instance variables of
, it would have no effect on
. Of course, there is no reason for
to modify its parameter, so this isolation between the two functions is
This kind of parameter-passing is called “pass by value” because it is
value of the class (or other type) that gets passed to the function.