SCJP Module-3 Question-1


 

SCJP Module-3 Question-1

The given example checks your knowledge of access specifier in Java and also heps in preparation for SCJP exam.

The given example checks your knowledge of access specifier in Java and also heps in preparation for SCJP exam.

Given a sample code:

1 public class Test {
2 public static void main(String[] args) {
3 new OuterClass();
}}

4 class OuterClass {
5 private int x = 9;

6 public OuterClass() {
7 InnerClass inner = new InnerClass();
8 inner.innerMethod();
}

9   class InnerClass {
10 public void innerMethod() {
11 System.out.println(x);
}}}

What will be the result of above code ?

(1) Prints 9
(2) Error during compilation at line 3
(3) Error during compilation at line 5
(4) Error during compilation at line 7

Answer:

(1)

Ads