public static void modify(int[] arr) {
arr[0] = 100;
}
public static void main(String[] args) {
int[] a = {1, 2, 3};
modify(a);
System.out.println(a[0]);
}What is printed?
- Acheck_circle
100
- B
Compilation error
- C
0
- D
1
Explanation
Array references are passed by value, but the value is a reference to the same array. The method modifies the underlying array, so a[0] is now 100.