at line 2, you are creating a clone of the array. then you assign that clone to an Object. As you might know, that int and every other primitive array is a sub-class of Object. But since this is a 2-D primitive array, so you are able to assign to an Object. You can think of a 1-D int array as an Object. So a 2-d int array as an array of 1-d int array. This is why the assignment is allowed...
ok but which values can be assigned to 1-d Object array?
1-d object array can store any type of an array except 1-d primitive arrays.
how values in 2-d array can b converted in to 1-d array?
values in 2-d array cannot be converted into 1-d array (at least directly without using any loop or something). I think you are confused here. The 2-d array converted into a 1-d array because we changed the type. We did not assign a 2-d int array into 1-d int array. We assigned a 2-d int array into a 1-d object array...
Originally posted by meera kanekal: Patrick and Ankit I found your explanation very helpful. But I don't understand why the output is 112. Could you please explain where that is coming from? Thanks, Meera
Because, i doesn't remain constant. It changes from 0 to 1 to 2 with each iteration of the for loop. Therefore, obj = 1, obj = 1 and obj = 2.