Hi Shanthisri,
An easy way to remember arrays and references to them when passed to methods is like this:
1. Ofcourse a copy of the reference (pointing to the array object) is passed when the method m1 in the above examples is called.
2. So references i1 and i2 in the method m1 is different from the references i1 and i2 in the main method. (it is like the array object is a Lock and the references are the Keys to open the Locks - so here we have two sets of Keys that open the same lock and both have the same name but in different methods)
3. As long as the i1 and i2 references in the method m1 are changed (for example i1 = i2 or int[] i3 = i1 etc), it does not affect the original array content (declared in the main method).
4. But if the i1 and i2 references in the method m1 change the individual array element values, it reflects in the original arrays. (For example i1[0] = i2[0] -> this will change the value in the original array declared in the main method).
So look for what is being changed the reference by itself or the array elements pointed by the references.
Hope this helps...and so you can see the results as they are.
Roopesh
SCJP 1.4 in progress.