(1) of the Point class private member variables are:
X: double, on behalf of the x coordinate
Y: double, on behalf of the y coordinate
(2) Point class members of the public methods are:
Point () : a constructor, the default x and y coordinates are 0
Point (double xx, double yy) : construction method, respectively, with two formal parameter xx, yy for member variables x and y are initialized,
Double GetX () : get x coordinates,
Double GetY () : get y,
(3) and then write a UsePoint contains the main method of class, create a Point class object, and call the method defined above,
CodePudding user response:
Package com. Ar;Public class UsePoint {
Public static void main (String arg c [])
{
//Point pointObj=new Point ();
Point pointParamObj=new Point (3, 5);
/* System. Out. Println (" x: "+ pointObj. GetX ());
System. The out. Println (" y: "+ pointObj. GetY ()); */
System. The out. Println (" x: "+ pointParamObj. GetX ());
System. The out. Println (" y: "+ pointParamObj. GetY ());
}
}
Package com. Ar;
Public class Point {
Private double x=0;
Private double y=0;
Point ()
{
Point System. Out. Print (" () ");
}
Point (double xx, double yy)
{
System. The out. Print (" Point (xx, yy) ");
X=xx;
Y=yy.
}
Public double GetX ()
{
Return the x;
}
Public double GetY ()
{
The return of y;
}
}