Share on Google+Share on Google+

SCJP Module-3 Question-1

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




Posted on: July 9, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.


Advertisement null