定义一个点类Point,包含2个成员变量x、y分别表示x和y坐标,2个构造方法Point()和Point(int x0,y0),
以及一个movePoint(int dx,int dy)方法实现点的位置移动,创建两个Point对象p1、p2,分别调用movePoint方法后,打印p1和p2的坐标
package ti;
public class Point {
int x;
int y;
public Point() {
}
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public void movePoint(int x, int y) {
this.x += x;
this.y += y;
}
}
package ti;
public class Text {
public static void main(String[] args) {
Point p1 = new Point(2, 3);
Point p2 = new Point(52, 89);
p1.movePoint(56, 87);
System.out.println(p1.x + "," + p1.y);
}
}