Java OCA OCP Practice Question 1966

Question

Which expressions, when inserted at (1), will result in compile-time errors?.

public class Main {
 static final Integer i1 = 1;
 final Integer i2 = 2;
 Integer i3 = 3;// w w  w  .j  ava2 s  .co m

 public static void main(String[] args) {
   final Integer i4 = 4;
   Integer i5 = 5;

   class Inner {
     final Integer i6 = 6;
     Integer i7 = 7;
     Inner (final Integer i8, Integer i9) {
       System.out.println(/* (1) INSERT EXPRESSION HERE */);
     }
   }
   new Inner(8, 9);
 }
}

Select the three correct answers.

  • (a) i1
  • (b) i2
  • (c) i3
  • (d) i4
  • (e) i5
  • (f) i6
  • (g) i7
  • (h) i8
  • (i) i9


(b), (c), and (e)

Note

(b) and (c) because i2 and i3 are instance fields that cannot be accessed from a static context, in this case from a local class in a static method.

(f) is not allowed because the local variable i5 is not declared final in the enclosing method.




PreviousNext

Related