A. :
int[] x = {1, 2, 3, 4};
int[] y = x;
, x y , 4.
x = new int[2];
Now we have changed the value of x, but we have not changed the value of y.
So now x has a length of 2, which is {0, 0}, and y still has a length of 4, which is {1, 2, 3, 4}, and here comes the difference ...
for (int i = 0; i < y.length; i++)
In the line above, we already know that y.length = 4 , so I am <4 .
System.out.print(y[i] + " ");
The above line will now output an array of y values โโrespectively, which are:
1
2
3
4
source
share