package point;
public class Point {
int x;
int y;
//无参构造器
public Point(){
}
//有参构造器
public Point(int x,int y){
this.x=x;
this.y=y;
}
//movePoint方法
public void movePoint(int dx,int dy){
this.x+=x;
this.y+=y;
System.out.println("坐标为("+this.x+","+this.y+")");
}
}
package point;
public class Test {
public static void main(String [] args){
//创建实例
Point p1=new Point(3,2);
Point p2=new Point(6,4);
p1.movePoint(p2.x,p2.y);
}
}
point移动
最新推荐文章于 2024-03-25 20:12:45 发布