Mutable MyPoint

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
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 =