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-Accessor
does not work if I create an object with a constructor in the
Main-Program
implementing a barrier in Main-Code so height never gets over 50
does not work if I want new objects of
CannibalGhost
later (and is a mess)writing it so
CannibalGhost
does not derive fromGhost
So I am able to write a new constructor and
set-Accessor
with a ceiling of 50. It worked but I wantCannibalGhosts
also 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
?