Big Moose Saloon
 Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies Register / Login

Object reference array assignment

Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 481

I don't get this reference assignment.
My ananlysis about line 5 is,a2[0] and a2[1] are one dimensinal arrays and a1 reference is also one dimensional array.so assignation is valid
My analysis about line 6,a3[0],a3[1],a3[2] are one dimensional array and a2 reference is two dimensional array.i thought it would be invalid.but this one compiles fine .How?Please explain.
My understanding about line 7,a3[0][1] is two-dimensional array and a2 reference is also two-dimensional array.so ithought it would valid.but this statement produce compilee error.Please explain
[ September 18, 2006: Message edited by: Shiva Mohan ]
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2398
a3[0][1] is a 1-dimensional array.
Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 481
Thanks for the reply Keith. In declaration of a3 is an three-dimensional array.Right?
In the statement a3[0][1]=a2;here a3 is two-dimensional array.How come a3 is one-dimensional.Please explain
Greenhorn

Joined: Sep 18, 2006
Posts: 3
it is one dimensional array
Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 481
At which line,a3 three-dimensional array is changed to one-dimensional.Please explain if possible?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 20526

50

Originally posted by Shiva Mohan:
Thanks for the reply Keith. In declaration of a3 is an three-dimensional array.Right?
In the statement a3[0][1]=a2;here a3 is two-dimensional array.How come a3 is one-dimensional.Please explain

a3 is "three-dimensional". a2 is "two-dimension". And a3[0][1] is one dimensional.

Henry

PS... I place the number of arrays in quotes, because technically, Java supports arrays of arrays -- not multidimensional arrays. (but for this debate, it's an okay interpretation.)

Meena R. Krishnan
Ranch Hand

Joined: Aug 13, 2006
Posts: 178
a3 is a 3-d array of size 3.(line 3 )

a3[0], a3[1],a3[2] each in turn is a 2-d array and each of size 2. (line 6) - since the value of a2 is being assigned to these.

a3[0][0],a3[0][1],a3[1][0],a3[1][1] each in turn is a 1-d array of size 1. ( each carrying the reference to A11 )

I agree. Here's the link: http://aspose.com/file-tools

subject: Object reference array assignment