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

 
 

Share on Google+Share on Google+
SCJP Module-4 Question-9
Posted on: July 9, 2010 at 12:00 AM
Advertisement
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() {
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

Answer :

(B)

Explanation :

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

Related Tags for SCJP Module-4 Question-9:


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.

Posted on: July 9, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com