Each constructor requires the user to supply different data.
Any of the three constructors can be used to create a Point
.
It is a matter of convenience which constructor you use.
Here is an example:
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" } }
For the compiler to be able to use the definition of Point
in the class library,
an import
must be used.
The statement import java.awt.*
*
says that everything defined in the library can be used
(although this program only uses the Point
class).
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?