wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes array object assignment ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "array object assignment ??" Watch "array object assignment ??" New topic
Author

array object assignment ??

Ajay Divakaran
Greenhorn

Joined: Jul 08, 2007
Posts: 22
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
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: 1296
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: array object assignment ??