Revised Picture

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:

First  value of message: Original Object 
First value of parameter: Original Object 
Second value of parameter: Hah! A second Object! 
Second value of message:   Original Object 

Revised Picture

In the revised program, the print() method created a new object and placed a reference to it into the parameter st. As long as you know what you are doing, this is OK.

Each color of line in the picture represents a different reference value. The picture shows the print() method changing the value in the formal parameter so that it refers to a second object.

two objects

Neither the original object, nor the variable message of the main() method are changed. The print() method can use its formal parameter just like any variable, including changing the value it holds.


QUESTION 9:

Could print() use the reference to the original String object to change the contents of that object?