The equals() Method

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 x value and the y value of each point is the same.

The equals() Method

The equals() method is defined for class Point to perform this test:

pointA.equals( pointB )   —— returns true if the two points
                             contain equivalent data

The example program shows this:

import java.awt.*;
class EqualsDemo
{
  public static void main ( String arg[] )
  {
    Point pointA = new Point( 7, 99 );    // first Point
    Point pointB = new Point( 7, 99 );    // second Point with equivalent data

    if ( pointA.equals( pointB ) )
      System.out.println( "The two objects contain the same data: " + pointA );
    else
      System.out.println( "The two objects are not equivalent: " + pointA + 
          " differs from" + pointB);     

  }
}

QUESTION 16:

What is the output of this program? (You might wish to copy-paste-and-run this program to check your answer.)