class Cat
{
private String name;
private int age;
private double weight;
private Color color;
public Cat(String name , int age , double weight , Color color){
this.name = name;
this.age = age;
this.weight = weight;
this.color = color;
}
public boolean equals(Object obj){
if(this == obj){
return true;
}
if(obj == null){
return false;
}
if(this.getClass() != obj.getClass()){
return false;
}
Cat cat = (Cat)obj;
return name.equals(cat.name)&&(age == cat.age)&&(weight == cat.weight) && (color.equals(cat.color));
}
最后的那段代码的equals()与重写后的equals()有什么关系!是不是重写的那个是专门给对象作比较的?还有
this.getClass()有没有this貌似都差不多,为什么呢? |