Home Tutorial Java Scjp Part4 SCJP Module-4 Question-20

 
 

SCJP Module-4 Question-20
Posted on: July 10, 2010 at 12:00 AM
The program given below tests your understanding of Inheritance and method overriding in core java.

Given below the sample code :

1   class Hotel {
2   public int bookings;
3   public void book() {
4   bookings++;
5   }
6   }
7   public class SuperHotel extends Hotel {
8   public void book() {
9   bookings--;
10  }
11  public void book(int size) {
12  book();
13  super.book();
14  bookings += size;
15  }
16  public static void main(String args[]) {
17  Hotel hotel = new Hotel();
18  hotel.book(2);
19  System.out.print(hotel.bookings);
20  }}

How can we correct the above code ?

1. By adding argument "int size" to the method book at line number 3.

2. By removing argument '2'  at  line number 18.

3. By creating object of "SuperHotel" subclass at line 17 & calling book(2) from it at line 18

4. No correction needed.

Answer:

(1) ,(2) &(3).

Explanation :

Because the method book() of the type Hotel doesn't have the arguments.

Related Tags for SCJP Module-4 Question-20:


Ask Questions?

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.