More about Objects and Classes

The relational operations on primitive data are ==, >=, <=, >, <, and !=. They compare two data values, when those values' type has an ordering. For example, integers are ordered by size or magnitude. The result of a relational operation is a boolean value: either True or False. The relational operators on objects like Strings are different, and they are expressed as methods. Pay special attention to the equality method, equals().

19. Alias


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?