• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

array object assignment ??

 
Ajay Divakaran
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic