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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "multidimensional array question" Watch "multidimensional array question" New topic
Author

multidimensional array question

Alfonso Harding
Ranch Hand

Joined: Feb 09, 2002
Posts: 35
From the following code:


Can someone please explain why the following assignment is legal:


and why is the following not legal.

thanks.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Originally posted by Alfonso Harding:
From the following code:


Can someone please explain why the following assignment is legal:


and why is the following not legal.

thanks.

b2 is a 4-dimensional array and b is a 2-dimensional array so when you have N subscripts following an N-dimensional array that will evaluate to a simple element. In the first statement you had b2 [0][1][0][0] which indeed evaluates to a simple byte and b [0][0] which also evaluates to byte. Now if you have fewer subscripts than dimensions, then it will evaluate to an array of N-S dimensions where S is the number of subscripts that follows the reference. In the second example you had b2 [1][1][0] or a 4-3=1 dimensional array. Java being a strong typed language vetos your trying to set an array to a primitive.


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: multidimensional array question
 
Similar Threads
Self Test Question on Arrays by Kathy's Book
Multidimensional Arrays
array
Doubt About the output of this Question
multi arrays