Java OCA OCP Practice Question 63

Question

Consider the following definition:

 1. public class Outer { 
 2.   public int a = 1; 
 3.   private int b = 2; 
 4.   public void method(final int c) { 
 5.     int d = 3; 
 6.     class Inner { 
 7.       private void iMethod(int e) { 
 8. //from   w w  w .  j  a va2 s  . c om
 9.       } 
10.     } 
11.   } 
12. } 

Which variables can be referenced at line 8? (Choose all that apply.)

  • A. a
  • B. b
  • C. c
  • D. d
  • E. e


A, B, C, E.

Note

Because Inner is not a static inner class, it has a reference to an enclosing object, and all the variables of that object are accessible.

A and B are correct, even if the fact that b is marked private.

Variables in the enclosing method are accessible only if those variables are marked final, so the method argument c is correct, but the variable d is not.

The parameter e is accessible, because it is a parameter to the method containing line 8.




PreviousNext

Related