SCJP Module-3 Question-8


 

SCJP Module-3 Question-8

The Program given below will test your knowledge of Inner classes and Outer classes in Java and help you for preparation of SCJP examination.

The Program given below will test your knowledge of Inner classes and Outer classes in Java and help you for preparation of SCJP examination.

Given below the sample code :

class OuterClass{
String s = "OuterClass ";

public static void main(String[] args) {
new OuterClass().new InnerClass();
}

OuterClass() {
System.out.print(s);
}

class InnerClass {
String s = "InnerClass";

InnerClass() {
System.out.print(s);
}
}
}

What will be the output of the following code ?

1.  It will give compile error.

2. Prints : OuterClass InnerClass

3. Prints : OuterClass

4. Prints : InnerClass

Answer :

(2)

Ads