The sample program given below test you knowledge inheritance and also prepares you for SCJP exam
The sample program given below test you knowledge inheritance and also prepares you for SCJP examGiven below the sample code :
class Hotel {
public int bookings;
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[]) {
Hotel hotel = new Hotel();
hotel.book(2);
System.out.print(hotel.bookings);
}
}
What will be the output ?
A) 2
B) Compilation fails.
C) 0
D) 1
(B)