Summary

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

If the == operator returns a true will the equals() method return a true, always?

Answer:

Yes.

Summary

The following table is a summary. Assume that each row is independent of the others.

code sectionpointA == pointB pointA.equals( pointB )
Point pointA = new Point( 21, 17 );
Point pointB = new Point( 21, 17 );
falsetrue
Point pointA = new Point( 21, 17 );
Point pointB = new Point( -99, 86 );
falsefalse
Point pointA = new Point( 21, 17 );
Point pointB = pointA;
truetrue


QUESTION 22:

Will pointA.equals(pointB) return the same true/false value as pointB.equals(pointA) ?