Given below the sample code :
class Hotel {
public int bookings=2;
public void book() {
bookings++;
}
}
public class SuperHotel extends Hotel {
public void book() {
bookings--;
}
public void book(int size) {
book();
super.book();
bookings += size;
}
public static void main(String args[]) {
SuperHotel Shotel = new SuperHotel();
Shotel.book(2);
System.out.print(Shotel.bookings);
}
}
Find the output of the following code :
1. Compile error
2. 2
3. 4
4. No output.
(3)
"SuperHotel" Subclass 's object "Shotel" calls the "book()"
method of it.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.