Yes. You have to be careful how you use the result, however.
Here is the example program (again!) with this modification:
import java.awt.*; class equalsDemo4 { public static void main ( String arg[] ) { Point pointA = new Point( 7, 99 ); // pointA refers to a Point Object Point pointB = pointA; // pointB refers to the same Object if ( pointA.equals( pointB ) ) { System.out.println( "The two variables refer to the same object," ); System.out.println( "or different objects with the same data." ); } else System.out.println( "The two variables refer to different objects" ); } } |
The picture of the situation is the same as before. But now the equals() method is used. It:
The fact that the object is the same object in step 1 and step 2 does not matter. The x's that are tested are the same, and the y's that are tested are the same, so the result is true.