Answer:
x = 3; y = 5 Enter PointDoubler x = 3; y = 5 x = 6; y = 10 Leave PointDoubler x = 6; y = 10
Still Call by Value
Here are some facts:
- Paramater passing is always call by value .
- If a method's parameter is a primitive data type, the method can change its own value for the parameter, but the change has no effect elsewhere.
- However, if a method's parameter is a reference to an object, the instance variables of the object can be changed (if they are public).
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).
QUESTION 12:
Look at the definition of the MyPoint class.
Think of a way to make MyPoint objects immutable.