I have a class called Occupant
and extended Occupant classes
for different occupant types such as Animal, Food, Tools, Treasure.
All occupants are placed on GridSquares
, A Square can hold up to 3 occupants.
Occupant class has a method to get all the Occupants on a GridSqure when the position is given. The method will return a Occupant Array with extended occupant classes.( E.G: An Animal, A Tool and A Food).
Occupant[] allOccupants = newGridSquare.getOccupants();
for ( Occupant oneOccupant : allOccupants)
{
if(oneOccupant.getStringRepresentation() == "A")
{
player.reduceStamina(oneOccupant.getDanger());
}
}
compiler cannot access getDanger
method in Animal class just because I already have assigned it as Occupant.
How can I access getDanger method in extended Occupant class Animal?