hi
in code 1:
you have passed a COPY of the refernce variables i1 and i2 in m1(i1,i2).
now these are COPIED into the m1(int[] i1,int[] i2) i1 and i2.These are actually the bit
pattern for referencing the arrays.
here in m1(),you are changing the
copied bit patterns in the method local variables.
but when the m1() completes, the original i1 and i2 still have their original copies with them.
So,the i1 i2 still refers to the original arrays,and hence the output.
in Code2:
here also you are passing the COPY of the reference variables in the method
which are again being COPIED into m1's i1 and i2.
BUT now you are using these reference bits to actually reach the original array and change the values inside it.
NOTE: while passing Object references to a method a copy of the reference is passed which can be used to change the values of the object.
The original reference remains the same.