-3
如何在后面的方法“public static void main(String [] args)”)中使用我的“public boolean equals方法”创建一个true或false值?*方法*调用布尔值
public Car(String color, double insurance)
{
this.color = color;
this.insurance = insurance;
}
public boolean equals(Car other)
{
if (this.color.equals(other.color) && this.insurance.equals(other.insurance))
{
return true;
}
else
{
return false;
}
}
我得到错误:在基本型双
(1)'等于(汽车等)'属于到Car类,这意味着你可以在Car实例上调用它们,比如'carInstance.euqlas()'(2)如果你想覆盖已经存在的equals方法,那么你需要使用equals(Object other)声明它'不等于(汽车其他)'。 – Pshemo
'if(c1.equals(c2))' - 但是你的equals方法被破坏了。它应该采用Object参数,而不是Car参数。 –
这段代码很奇怪。我很努力去理解你要做什么。等号的整体应该是'this.color.equals(other.color)&& this.insurance.equals(other.insurance;',而且你甚至从来没有打过'equals'。另外,写'if(true)是完全没用的 – Carcigenicate