/* Code bit */
int[] arr1={1,2,3};
int[] arr2=new int[4];
arr2=arr1;
System.out.println(arr2[3]);
---
The above code throws a java.lang.ArrayIndexOutOfBoundsException.
Code insight:
1.Two array objects were declared and initialized.
so two references and two objects are created.
2.Then the reference of arr2 is made to point to the object of arr1 by assigning its reference.
3.Hence after assignment two references are pointing to one object,making
the empty array eligible for Garbage Collection.
4.arr2 has only 3 elements and max index is 2,hence the exception.
Its simple assignment of objects to references.No value copy is made or element copy is done.
Hope this clears your doubt.