public class Point {
double x,y;
public Point(float x,float y ){
this.x = x;
this.y = y;
}
void setX(double x){
this.x = x;
}
void setY(double y){
this.y = y;
}
double getDistance(Point p){
return (x-p.x)*(x + p.x) +(y - p.y)*(y + p.y);
}
public static void main(String[] args) {
Point p = new Point(1,2);
Point p1 = new Point(0,0);
System.out.print(p.getDistance(p1));
p.setX(5.0);
System.out.print(p.getDistance(p1));
}
}
看看java的Point源码