ProgrammingModerateAccenture · Capgemini technical pattern

Which line fails to compile?

Which line fails to compile?
final int[] arr = {1, 2, 3};
arr[0] = 10;          // L1
arr = new int[3];      // L2
System.out.print(arr[0]); // L3
  1. A. L2
  2. B. L1
  3. C. L3
  4. D. Both L1 and L2

Correct answer: A. L2

final fixes the reference, not the object: the array’s contents can change (L1 is fine), but arr cannot be pointed at a new array (L2 fails).

More OOP with C++ and Java questions

Exams that ask this topic