Different Objects, Equivalent Data

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:

The two objects contain the same data: java.awt.Point[x=7,y=99]

Different Objects, Equivalent Data

Here is a picture showing the situation. There are two distinct objects (each constructed out of different bytes of memory). The equals() method returns true because the data is equivalent.

two variables, two objects with equivalent data

QUESTION 17:

Could the == operator be used in this program instead of the equals() method?