Given final int a = {1, 2}; a = 9; System.out.println(a);, what is the result?
Correct answer B. It prints 9
Explanation
A final variable can be assigned only once, but for a reference that restricts the reference and not the object it points to. The array itself remains mutable, so a[0] = 9 is legal and 9 is printed. The statement a = new int[2] would be the compile-time error, since it reassigns the variable.
Answer checked How we write and check questions
Discussion