Let's look at how this works.
First of all, you have to understand that variables of non-primitive types in
java are
references. They point to an object somewhere in memory. Variables of array types, such as ref1 and ref2 in this code, are references to array objects (arrays are objects).
int[] ref1 = {2, 5, 4};
int[] ref2 = {3, 2, 1};
Here, two arrays are created and the variables ref1 and ref2 refer to the two arrays.
ref2[1]++;
ref2 = ref1;
In the first of these two lines, you increment the element at index 1 in the second array. But then you make ref2 refer to the same array object as what ref1 refers to. Note that we loose the reference of the array that ref2 initially referred to. The line with the increment has essentially no effect, since we forget about that array object that we just modified in the second line.
ref2[2] += ref1[0];
Now we increment the element at index 2 of the array that ref2 refers to, with the value at index 0 of the array that ref1 refers to.
But note that ref2 and ref1 refer to the same array object! So whatever you change through ref2 is also seen when you look at the array through ref1.
Since ref1[0] == 2, the array will now contain {2, 5, 6}.