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().

14. Dangerously Similar Program


No. Constructors always create new objects. (They might get data from an old object,
but a completely separate object will be constructed using a different chunk of main memory.)

Dangerously Similar Program


The example program has been modified to create a second Point object.

In the "After" picture, the first object is shaded to emphasis that it is now "garbage." The reference variable pt now refers to the newly created object.

import java.awt.*;
class ChangingData2
  public static void main ( String arg[] )
    Point pt = new Point( 12, 45 );            // construct a Point
    System.out.println( pt );     

    pt = new Point( -13, 49 ) ;                // construct a new Point
    System.out.println( pt ); 

Question 14:

What will this second version of the program output to the monitor?