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

 
 

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

Advertisement

Related Tags for SCJP Module-3 Question-2:


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