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

 
 

SCJP Module-4 Question-11
Posted on: July 10, 2010 at 12:00 AM
The program given below checks your knowledge of Inheritance in Java and also access restriction on methods in program.

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.

Answer :

(3)

Explanation :

"SuperHotel" Subclass 's object  "Shotel" calls the "book()" method of it.

Related Tags for SCJP Module-4 Question-11:


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.