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

4. Multiple Constructors


Answer:

The different constructors require different parameters. 
(Different types of data are supplied to the constructors.)

Multiple Constructors

import java.awt.*;      // import the package that contains Point
class PointEg1
{

  public static void main ( String arg[] )
  {
    Point a, b, c;              // reference variables

    a = new Point();            // create a Point at (0,  0); 
                                // save the reference in "a"
    b = new Point( 12, 45 );    // create a Point at (12, 45); 
                                // save the reference in "b"
    c = new Point( b );         // create a Point containing data equivalent
                                // to the data referenced by "b"
  }
}   

Any of the three constructors can be used to create a Point. It is a matter of convenience which constructor you use. Look at the example program.

To use the definition of class Point, import the package that contains it. The statement:

import java.awt.*

says to use the AWT package that comes with Java. The * says that everything defined in the package can be used (although this program only uses the Point class).


Question 4:

Say that the program has just been loaded into main memory and is just about to start running.

How many reference variables are there?

How many objects are there?