help on overriding - java
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);
}
ttboy04
Junior Poster in Training
53 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
Inside the overridden method use code that checks the color. If it is purple, don't change it
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
ttboy04
Junior Poster in Training
53 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0