go to previous page   go to home page   go to next page hear noise

Answer:

No. The == operator tests if two reference variables refer to the same object.


Testing Two Reference Variables

two variables, two objects with equivalent data

Here is the program, modified to use the == operator.

The objects are the same as before so the picture is the same as on the previous page.

import java.awt.*;
class EqualsDemo2
{
  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 == pointB  )
      System.out.println( "The two variables refer to the same object" );   
    else
      System.out.println( "The two variables refer to different objects" );  

  }
}

The == operator looks at the references in the two reference variables to see if those reverences are identical.


QUESTION 18:

What is the output of this program?


go to previous page   go to home page   go to next page