欧几里德平面中的点

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是什么方法?有什么用。哪些类型能用它?
不知我说的可详细,请赐教》》》》
...全文
69 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
stevech 2004-04-10
  • 打赏
  • 举报
回复
getClass是java.lang.Object中的方法,返回一个实例的运行时类型。如
Object str = new String("abc");
str.getClass()将返回java.lang.Object;而:
String str = new String("abc");
str.getClass()将返回java.lang.String。具体可参看Java reflection部分。
hashCode为每一个实例产生一个唯一的序列号。可重载。
任何Java类均可使用。

50,499

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧