Home Tutorial Java Scjp Part3 SCJP Module-3 Question-10


Share on Google+Share on Google+
SCJP Module-3 Question-10
Posted on: July 12, 2010 at 12:00 AM
The given example will test your understanding of Super class and Sub class in Java and their object initialization.

Given below the sample code :

class SuperClass {
public static void main(String[] args) {
new SubClass();

SuperClass() {
System.out.print("Inside SuperClass ");

class SubClass extends SuperClass {
SubClass() {
System.out.print("Inside SubClass");

What is the output of the following code ?

1. Inside SuperClass

2. Inside SubClass

3. It will give compile error

4. Inside SuperClass Inside SubClass.

Answer :


Explanation :

Because the 'SuperClass' constructor automatically run, therefore the first output would be "Inside SuperClass" & after it, the instance of the "SubClass" is called which in turn prints "Inside SubClass".


Related Tags for SCJP Module-3 Question-10:

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

Recommend the tutorial

Advertisements Advertisements