Here is my code:
interface Dwelling {
int getNumberOfOccupants();
}
public class House extends Building implements Dwelling {
@Override
public int getNumberOfOccupants() {
return occupants;
}
}
public class ApartmentBuilding extends HighRise implements Dwelling{
@Override
public int getNumberOfOccupants() {
totalOccupants = numberOfFloors * occupantsPerFloor;
return totalOccupants;
}
}
public class Village extends Building{
public int getPopulation(){
size = House.getNumberOfOccupants() + ApartmentBuilding.getNumberOfOccupants();
return size;
}
}
When I try to add the getNumberOfOccupants()
methods from the House
and ApartmentBuilding
classes I am getting a Non-static method 'getNumberOfOccupants()' cannot be referenced from a static context error. I am not sure how I can add these methods to produce the getPopulation()
method