Say that the program has just been loaded and is just about to start running.
How many reference variables are there? 3
How many objects are there? Zero
Here is a picture of the variables just as the program starts running.
No objects have been instantiated yet, so the reference variables
a
, b
, and c
do not refer to any object.
To emphasis this, a slash has been put through the box that represents each variable.
Here is the program again:
import java.awt.*; // import the class library where Point is defined 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" } } |
This program:
a
, b
, and c
,
which may refer to objects of type Point.a
.b
.c
.Once each Point object is instantiated, it is the same as any other (except for the values in the data). It does not matter which constructor was used to instantiate it.