0
public class BnBReservation extends Reservation{

public BnBReservation(String resName, Hotel hot, String roomType, int numNights){
    super(resName);
    new HotelReservation(resName, hot, roomType, numNights);    
}

so i have a class called hotelreservation and bnbreservation and they are both subclass of superclass reservation, would above code allow me to create a object of HotelReservation when I create an object of BnBReservation?

  • 1
    although you don't show us your `HotelReservation` class to us, you are creating a new object indeed but you are not storing that object to a reference value, try doing `hotelRes = new HotelReservation(resName, hot, roomType, numNights); ` when `hotelRes` is a member of your BNBReservation class – Alex Andrade Feb 07 '20 at 21:14
  • 1
    Is this what you are trying to do? [Is it possible in Java to have a constructor return another instance of the class, rather than constructing/returning itself?](https://stackoverflow.com/questions/20898287/is-it-possible-in-java-to-have-a-constructor-return-another-instance-of-the-clas) – Cardinal System Feb 07 '20 at 21:15

0 Answers0