哈哈多谢帮忙啊,也就是说一个类的方法是相对于其实例对象的class Point { int x,y,z; Point (int x , int y , int z){ this.x=x; this.y=y; this.z=z; } void setX(int x){this.x=x;} int getDistance(Point p){ return (x-p.x)* (x-p.x)+(y-p.y)*(y-p.y)+(z-p.z)*(z-p.z); } }class TestDemo { public static void main(String[] args) { Point p1 =new Point(2,2,2); Point p2 =new Point(0,0,0); System.out.println(p1.getDistance(p2)); } }
{
int x,y,z;
Point (int x , int y , int z){
this.x=x;
this.y=y;
this.z=z;
}
void setX(int x){this.x=x;}
int getDistance(Point p){
return (x-p.x)* (x-p.x)+(y-p.y)*(y-p.y)+(z-p.z)*(z-p.z);
}
}class TestDemo
{
public static void main(String[] args)
{
Point p1 =new Point(2,2,2);
Point p2 =new Point(0,0,0);
System.out.println(p1.getDistance(p2));
}
}