合聚咖

合聚咖

Java定义一个Point(点)类

admin

public class Point

{

public static void main(String[] args)

{

Point p1=new Point();

Point p2=new Point(1,2);

p1.show();

p1.move(3,4);

p1.show();

p2.show();

p2.move(5,6);

p2.show();

}

Point()

{

this(0,0);

}

Point(float x,float y)

{

this.x=x;

this.y=y;

}

void move(float x,float y)

{

this.x=x;

this.y=y;

}

void show()

{

System.out.printf("(%f,%f)",x,y);

System.out.println();

}

private float x,y;

}