class Demo
{
private int num;
Demo(int num)
{
this.num=num;
}
public boolean equals(Object obj) //换成(Demo d) 下面第一行去掉,好像也能运行,为什么老师说这样不行啊?
{
Demo d=(Demo)obj;
return this.num==d.num;
}
}
class ObjectDemo
{
public static void main(String[] args)
{
Demo d1=new Demo(4);
Demo d2=new Demo(5);
System.out.println(d1.equals(d2));
}
} |
|