go to previous page   go to home page   go to next page

Answer:

x = 3; y = 5
Enter PointDoubler
x = 3; y = 5
x = 6; y = 10
Leave PointDoubler
x = 6; y = 10

Review

1. Parameter passing is always call by value.

2. If a method's parameter is a primitive data type, the method can change the value held in its parameter, but that change has no effect elsewhere.

3. However, if a method's parameter is a reference to an object, the method can use the reference to access the object and then change the instance variables of the object (unless they are private or in a different package).

4. The value in 3 is a reference to an object. The invoked method has its local copy of this reference and can't change the value of the reference held by the caller.

5. 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.


QUESTION 12:

Look at the definition of the MyPoint class. Think of a way to make MyPoint objects immutable.