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

 
 

SCJP Module-3 Question-2
Posted on: July 9, 2010 at 12:00 AM
This sample program check your knowledge of Inner class and outer class in Java.

Given a sample code:

1 public class Test {
2 public static void main(String[] args) {
3 OuterClass.InnerClass i = new OuterClass.new InnerClass();
4 i.innerMethod();
5 OuterClass o = new OuterClass();
6 o.x=5;
}}

7 class OuterClass {
8 public int x = 9;

9 public OuterClass() {
10 InnerClass inner = new InnerClass();
11 inner.innerMethod();
}

12 class InnerClass {
13 public void innerMethod() {
14 System.out.print(x);
}}}

What will be the result of above code ?

(1) Prints 555
(2) Error during compilation at line 6
(3) Error during compilation at line 11
(4) Prints 999

Answer:

(4)

Related Tags for SCJP Module-3 Question-2:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.