posted 21 years ago
Hi Veena,
What I understood about this example:
this a for effect to clone the double dimensional array referenced by i to a single dimensional one of type object.
Now, each element of obj is itself an int array:
obj[0] = {1,2}
obj[1] = {0,1,2}
obj[2] = {-1,0,2}
The explicit cast into an int array avoids a compiler error (an implicit cast can't be done from a class -here Object because obj[i] is of typer Object- to an array) and because obj[i] is an array of type integer, there's also no runtime error.
so first loop:
int [] ia = {1,2};//ia[0] = 1
System.out.println(1);
second loop:
int [] ia = {0,1,2}; //ia[1] = 1
System.out.println(1);
third loop:
int [] ia = {-1,0,2}; //ia[2] = 2
System.out.println(2);
So output gives: 112
Hope this helps,
Cyril.
SCJP 1.4, SCWCD, SCBCD, IBM XML, IBM Websphere 285, IBM Websphere 287