Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot reference roomNumber before supertype constructor has been called

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;
   }
}
like image 872
Darren Burgess Avatar asked Feb 11 '26 08:02

Darren Burgess


1 Answers

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)

like image 147
yurib Avatar answered Feb 12 '26 20:02

yurib



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!