class Point{
private double x;
private double y;
public Point(double x,double y){
this.x=x;
this.y=y;
}
public void setX(double x){
this.x=x;
}
public double getDis(Point p){
return Math.sqrt((this.x-p.x)*(this.x-p.x)+(this.y-p.y)*(this.y-p.y));
}
}
public class A{
public static void main (String [] args)
{
Point point1=new Point(3.0,4.0);
Point point2=new Point(0.0,0.0);
System.out.println(point1.getDis(point2));
point1.setX(9.0);
System.out.println(point1.getDis(new Point(2.0,4.0)));
}
}
运行结果: