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

11. Example Program Extended


Answer:

Yes. The method just returns a reference to the String itself. No new object is created.

Example Program Extended

          
import java.awt.*;
class PointEg3
{

  public static void main ( String arg[] )
  {
    Point a = new Point();              // declarations and construction combined
    Point b = new Point( 12, 45 );
    Point c = new Point( b );

    System.out.println( a ); // create a temporary String based on "a", print it out
    System.out.println( b ); // create a temporary String based on "b", print it out
    System.out.println( c ); // create a temporary String based on "c", print it out
  }
}            


The example program has been changed, yet again. The program prints out:

java.awt.Point[x=0,y=0]
java.awt.Point[x=12,y=45]
java.awt.Point[x=12,y=45]

This program is deceptively short. However, its execution calls for quite a bit of activity.


Question 11:

Just as the program is about to close, how many objects have been created?

How many object references are there?

Has any garbage been created?