Share on Google+Share on Google+

SCJP Module-4 Question-11

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() {

public class SuperHotel extends Hotel {
public void book() {

public void book(int size) {
bookings += size;

public static void main(String args[]) {
SuperHotel Shotel = new SuperHotel();;

Find the output of the following code :

1. Compile error

2. 2

3. 4

4. No output.

Answer :


Explanation :

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


Posted on: July 10, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.