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

Answer:

x = 3; y = 5
x = 45; y = 83

Mutable MyPoint

changing an object

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.

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.


QUESTION 11:

What is the output of the program?

x = y =

Enter PointDoubler

x = y =

x = y =

Leave PointDoubler

x = y =