0

I am trying to override setColour in the subclass callled ObjectB in the public void setColour(Colour xColour) method. So the OBjectB cannot change to purple. Can you see where I have gone wrong because the ObjectB is currently changing to purple colour. Please reply only if you know the answer. I know its in the public void setColour(Colour xColour) method but I don't know how to change the code.

Thanks in advance.

public class ObjectA
{
  private Colour acolour;

}

public ObjectA()
{

 acolour = PURPLE;
}

public Colour getColour()
{
      return acolour;
}


public void setColour(Colour xColour)
{
     acolour = xColour;
     update("acolour");
      
}

public void purple()
{
     setColour(Colour.PURPLE);
}


public void sliver()
{
     setColour(Colour.sliver);
}

public void orange()
{
     setColour(Colour.orange);
}

public class ObjectB extends ObjectA
{
    colourY = Colour.GOLD;

}

 public Colour getColour()
  {
   return colourY;
  }

public void setColour(Colour xColour)
   {
       colourY = xColour;
       this.update("colourY");
   }


public void blue()
   {
      setColour(Colour.BLUE);
   
   }
   
    public void GREY()
   {
      setColour(Colour.GREY);
  
   }
   
    public void gold()
   {
      setColour(Colour.GOLD);
   }

Edited by peter_budo: Please do not use CODE SNIPPED for posting question. Use FORUM THREAD.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by ttboy04
1

Inside the overridden method use code that checks the color. If it is purple, don't change it

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.