int[][] a = {{1,2},{3,4}}; Object o1 = a; /* how can 2-D array be assigned to a single object reference.Should it not bw Object[][] ??*/
Collins Mbianda
Ranch Hand
Joined: Aug 11, 2007
Posts: 259
posted
0
Even a is a 2-D array, it's an abject and for that reason you can assign it to a simple object.
You can do this: Object o1 = a; (you can assign a n-D array to an Object). But you cannot do this: int[]o1= a; (you cannot assign a 2-D array to a 1-D array). [ August 19, 2007: Message edited by: Collins Mbianda ]
SCJP 5.0 | SCWCD 1.4
Garrett Rowe
Ranch Hand
Joined: Jan 17, 2006
Posts: 1295
posted
0
you cannot assign a 2-D array to a 1-D array
This is legal:
An int[] is an Object. An int[][] is an array of int[], therefore the assignment is legal.
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter