I've got a BetterBuilding class which extends Building, and a BetterElevator class which extends Elevator. Building, in its constructor, fills up an array Elevator[] elevators with Elevator objects. Now, I'm trying to create the BetterBuilding constructor as follows:
public BetterBuilding(File f) {
super(f);
for(int i=0; i<elevatorNum; i++) {
elevators[i] = new BetterElevator(20);
}
System.out.println(elevators[0].test());
}
So basically, I tried to use the superclass constructor, then change the content of the elevators array to now contain a BetterElevator on position 0. But, when I try to call elevators[0].test(), I get an error saying that elevators[0] is an Elevator (test() is a method only available to BetterElevators). What am I doing wrong? Thanks in advance!