欧几里德平面中的点
Sanco 2004-04-10 01:18:37 下面的程序定义了Point类,我的问题标在代码中
public class Point{
protected double x,y;
public Point(double x,double y)
{ this.x=x;
this.y=y;
}
public double getX()
{return x;
}
public double getY()
{return y;
}
public Point getLocal()
{ return new Point(x,y);
}
public void setLocal(double x,double y)
{ this.x= x;
this.y= y;
}
public void translate(double dx,double dy)
{ x+= dx;
y+= dy;
}
public boolean equals(Object ob)
{ if(ob==this) return true;
if(ob.getClass()!=this.getClass()) return false;
Point point=(Point)ob;
return(x==point.x&&y==point.y);
}//问题1
public int hashCode()
{ return(new Double(x).hashCode()+(new Double(x)).hashCode());
}//问题2
public String toString()
{ return new String("("+(float)x+" ,"+(float)y+")");
}
}
以上都编译通过,并且能用主类调用。
问题1:getClass是什么方法?有什么用。哪些类型能用它?
问题2:hashCode是什么方法?有什么用。哪些类型能用它?
不知我说的可详细,请赐教》》》》