This code taken from a mock exam:
I have some questions regarding a few lines of this code:
1. Line 4 It clones 'a' and put it in an Object 'obj' array.
My understanding of this is that an array of single dimension is created where each element contains an array itself. So the content of each dimension of 'obj' will be something like this:
obj[0]={1,2}
obj[1]={0,1,2}
obj[2]={-1,0,2}
Now, if I were to modify the call in line 4 to this:
Object[][] obj = (Object[][])a.clone();
it would fail!
My explanation is that it failed because I am trying to cast each element of 'a', which is of primitive type, to an Object type; as if I issued the following statement:
obj[0][0]=1;
obj[0][1]=2;
:
Am I right on this assumption?
2. Lines 6 & 7 This one I cannot understand.
The way I see it, each element of 'obj' is assigned to a new array 'ia', similar to this one:
ia[0]=obj[0]; // {1,2}
ia[1]=obj[1]; // {0,1,2}
ia[2]=obj[2]; // {-1,0,2}
Now how can line 7 print the basic elements of 'a' by just using a single dimension of 'ia'?
Tks.
Al