Share on Google+Share on Google+

SCJP Module-4 Question-9

The sample program given below test you knowledge inheritance and also prepares you for SCJP exam

Given below the sample code :

class Hotel {
public int bookings;
public void book() {

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

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

public static void main(String args[]) {
Hotel hotel = new Hotel();;

What will be the output ?

A)  2
B) Compilation fails.
C) 0
D) 1

Answer :


Explanation :

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


Posted on: July 9, 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.