This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, Clone method creates a copy of the object.so,object 'a' is cloned and is stored in 'obj' array.Now length of 'obj' array is 3.Let us go through the loop now. when i=0, ia=obj so ia,obj refer to a. hence ia is same as a which is 1. when i=1 ia=obj ia,obj refer to a so ia is same as a which is 1 again. when i=2 ia=obj ia,obj refer to a so ia is same as a which is 2 Hope this helps...
Joined: Apr 19, 2005
Can you explain how the array length is 3? We are making a clone of two dimensional array into one dimensional array.
Joined: Feb 26, 2005
Hi, The length of array a is 3.so obj.length is also 3.That is 'a' has three elements. Dimensional arrays are considered as array of arrays. Now, a has three elements which are references to other array.So a.length is 3.
a is again a array of 2 elements .so,length of a is 2. length of a and a is 3. Hope this helps...