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 a program that creates some Points:
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.*