int[] a = {1, 2, 3};
int[] b = new int[a.length];
for (int i = 0; i < a.length; i++) {
b[i] = a[i];
}
b[0] = 99;
System.out.println(a[0] + " " + b[0]);What is printed?
- Acheck_circle
1 99
- B
0 99
- C
1 1
- D
99 99
Explanation
A new array is allocated and elements are copied one-by-one. Now a and b refer to different arrays, so modifying b[0] does not affect a[0].