CannibalGhost : Ghost (CannibalGhost dervies from Ghost)
CannibalGhost can eat any sort of Ghosts and get their Height added to his Height. However Ghosts should be able to be as big as they want, while CannibalGhosts should only be at a maximum Height of 50. It can't surpass under any circumstances. Not via. set-accessor and not via constructor.
I have tried so far:
override
Constructor:Can't override constructor
implementing a if(
height >= 50) inSet-Accessordoes not work if I create an object with a constructor in the
Main-Programimplementing a barrier in Main-Code so height never gets over 50
does not work if I want new objects of
CannibalGhostlater (and is a mess)writing it so
CannibalGhostdoes not derive fromGhostSo I am able to write a new constructor and
set-Accessorwith a ceiling of 50. It worked but I wantCannibalGhostsalso to be a Ghost (derive from Ghost)
Summary:
How can I set the property Height of CannibalGhost to max 50, but not in the base class Ghost?