您超载
equals而不是覆盖它。要覆盖
Object的
equals方法,您必须使用相同的签名,这意味着参数必须是
Object类型。
改成:
@Overridepublic boolean equals(Object other){ if (!(other instanceof Animal)) return false; Animal otherAnimal = (Animal) other; return (this.legs==otherAnimal.legs) && (this.getClass().getName().equals(otherAnimal.getClass().getName()));}


