Java OCA OCP Practice Question 1670

Question

Which statements, when inserted at (1), will cause a compilation error?.

public class Main {
  static void main(String[] args) {
    int a = 0;/*w w  w.ja v a 2  s.co  m*/
    final int b = 1;
    int[] c = { 2 };
    final int[] d = { 3 };
    useArgs(a, b, c, d);
  }

  static void useArgs(final int a, int b, final int[] c, int[] d) {
    // (1) INSERT STATEMENT HERE.
  }
}

Select the two correct answers.

  • (a) a++;
  • (b) b++;
  • (c) b = a;
  • (d) c[0]++;
  • (e) d[0]++;
  • (f) c = d;


(a) and (f)

Note

A value can only be assigned once to a final variable.

A final formal parameter is assigned the value of the actual parameter at method invocation.

Within the method body, it is illegal to reassign or modify the value stored in a final parameter.

This causes a++ and c = d to fail.

Whether the actual parameter is final does not constrain the client that invoked the method, since the actual parameter values are assigned to the formal parameters.




PreviousNext

Related