0

Good morning, I need to check if an object's color is the same of another's color. I tried the most classical way to do it. Here is how:

boolean Color checkColor()
{
    if(obj1.getColor()==obj2.getColor)
        return true;
    else
        return false;
}

In another method I did this to check if it functions:

public String ToString()
{
    if(checkColor()==true)
        return "OK";
    else
        return "NO";
}

this way does not work. How can I check if two colors are the same? is there another way to do it? Or this method is correct but I wrong something else? Thank you very much

  • `" I tried the most classical way to do it."` -- that's hardly "the most classical way to do it". It's the most classical way to check for *reference equality*, that two variables refer to the same object, but that's not what you want. You want functional equality which in Java is classically done using the `equals(...)` method. – Hovercraft Full Of Eels Feb 20 '16 at 15:34
  • Thank you mister!!!sorry for my faults but I am not a proefessional programmer like you ;) – Veronica Caterina Feb 20 '16 at 15:36

0 Answers0