public static void replace(int[] arr) {
arr = new int[]{9, 9, 9};
}
public static void main(String[] args) {
int[] a = {1, 2, 3};
replace(a);
System.out.println(a[0]);
}What is printed?
- A
Compilation error
- B
0
- Ccheck_circle
1
- D
9
Explanation
Reassigning the parameter arr only changes the local copy of the reference. The caller's variable a still refers to the original array, so a[0] is still 1.