alias-detector

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

What is the output of the program?

Answer:

The two variables refer to the same object

alias-detector

Remember that the == operator looks only at variables. If two variables contain a reference to the same object, the operator evaluates to true. Think of the == operator as an alias-detector. Here is a picture of the situation of the last example program:

two variables, both pointing at the same object

QUESTION 20:

(Thought question:) Could the equals() method be used with aliases, as in this program?