int[] a = {1, 2, 3};
int[] b = a;
b[0] = 99;
System.out.println(a[0]);What is printed?
- Acheck_circle
99
- B
1
- C
0
- D
Compilation error
Explanation
int[] b = a does not copy the array; it makes b refer to the same array. Modifying b[0] also changes a[0]. To make a real copy, you must allocate a new array and copy elements.