i have created two classes Standard and Family which extend abstract class Room, when compiling the Standard class i am met with the error "cannot reference roomNumber before supertype constructor has been called" but i cannot understand why, any help would be appreciated.
Room
public abstract class Room
{
public int roomNumber;
public String roomType;
public boolean ensuite;
public boolean available;
public Room(int roomNumber, boolean enSuite)
{
this.roomNumber = roomNumber;
ensuite = enSuite;
available = false;
}
}
Standard
public class Standard extends Room
{
private int roomNumber;
private int childCap;
private int adultCap;
public Standard(int theNumber, int kidsCap, int adultsCap)
{
super(theNumber, roomNumber);
childCap = childsCap;
adultCap = AdultsCap;
}
}
super(theNumber, roomNumber);
when calling a super constructor it must be the first thing you do. you're trying to send the private field roomNumber as a parameter.
on a side note, the Room constructor takes an int and a boolean value, while you are sending two ints.
public Room(int roomNumber, boolean enSuite)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With