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.
Note: 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.
Here is the example program with another class:
The picture shows the situation when the twice()
method of the PointDoubler
object is active.
The method has a reference to the single MyPoint
object
that is present and can alter the data in that object.