问一个java重写的问题
class Cat {
public String furcolor;
public int weight;
public int height;
Cat(String furcolor, int weight, int height) {
this.furcolor = furcolor;
this.weight = weight;
this.height = height;
}
public boolean equals(Object obj) {
if(obj == null) {
return false;
}
else {
if(obj instanceof Cat) {
Cat cat = (Cat)obj;
if(this.furcolor == cat.furcolor && this.weight == cat.weight&&this.height == cat.height) {
return true;
}
}
return true;
}
}
}
public class TestEquals {
public static void main(String[] args) {
Cat c1 = new Cat("red",10,5);
Cat c2 = new Cat("red",10,5);
System.out.println(c1 == c2);
System.out.println(c1.equals(c2));
}
}
请问equals 写在TestEquals里面为什么编译时报错呢?Cat里面就行