posted 20 years ago
The array object is created in the heap. The value of the address of the array object is passed to the fix() method. The value of an element is chaged in the method and the same address of the array object is returned back to the main method where it is assigned back to a2. So essentially a1 and a2 are pointing to the same array-object on the heap.
You have passed the address to the array object to the fix method
The first element of the array object now holds 7, so the modified array
holds {3,7,5} and you return back the address of the array. Both a1 and a2 point to the same array object on the heap.
So now when you add the elements of the array, it holds 3+7+5=15