x = 3; y = 5 x = 45; y = 83
As the example program shows,
a MyPoint
object can be changed
by any method that has a reference to it.
If a reference to a MyPoint
object is passed
as a parameter, then the invoked method can use that reference to change the
public instance variables of the object.
The picture shows the situation when the twice()
method of the PointDoubler
object is active,
just after that method has been called by the statement
dbl.twice( pt );
The twice()
method is called with a reference to the MyPoint
object
and so can alter the data in that object.
What is the output of the program?
x = y =
Enter PointDoubler
x = y =
x = y =
Leave PointDoubler
x = y =