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

Answer:

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

Mutable MyPoint

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:

changing an object

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.


QUESTION 11:

What is the output of the program?

x =   y = 

Enter PointDoubler x = y =
x = y =
Leave PointDoubler
x = y =