Given static void f(int a) { a = new int {9}; }, what does int b = {1}; f(b); System.out.println(b); print?
Correct answer D. 1
Explanation
Java passes every argument by value, and for an array that value is a copy of the reference. Reassigning the parameter a only changes the local copy, so b still refers to the original array and 1 is printed. Had the method executed a[0] = 9 instead, the shared array would change and 9 would appear.
Answer checked How we write and check questions
Discussion