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

 
 

Share on Google+Share on Google+
SCJP Module-4 Question-11
Posted on: July 10, 2010 at 12:00 AM
Advertisement
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.

Advertisement

Related Tags for SCJP Module-4 Question-11:


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 10, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com