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

Answer:

The two variables refer to different objects

Alias

Here is a further modified program:

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

  }
}

It is possible to have two (or more) reference variables refer to the same object. The modification to the program that does that.

Only one object has been created (because there is only one new operator.) The second statement:

Point pointB = pointA; 

copies the reference that is in pointA into the reference variable pointB.

Now both reference variables point to the same object.

alias: When two or more reference variables refer to the same object, each variable is said to be an alias.

QUESTION 19:

What is the output of the program?


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