x = 3; y = 5 Enter PointDoubler x = 3; y = 5 x = 6; y = 10 Leave PointDoubler x = 6; y = 10
Here are some facts:
These facts are consistent with call by value. The "value" is a reference to the object. The invoked method has its local copy of this reference and can't change the value of the reference held by the caller. However, the invoked method can change the object.
Of course, even if a method has a reference to an object,
the object can be changed only if the object allows changes to be
made (either with public
instance variables or through access methods).
Look at the definition of the MyPoint
class.
Think of a way to make MyPoint
objects immutable.