File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Question about One-Dimensional and Two-Dimensional Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Question about One-Dimensional and Two-Dimensional Arrays" Watch "Question about One-Dimensional and Two-Dimensional Arrays" New topic
Author

Question about One-Dimensional and Two-Dimensional Arrays

Sam Guthrie
Greenhorn

Joined: Nov 13, 2012
Posts: 1


Hello I've been looking at questions from the SCJP Sun JAVA questions these days, and I came across this one that I don't quite understand




C. b2[0][1][1] = b;

D. b2[0][1][1] = b[1][0];


Can someone explain why are these choices wrong?

The solutions say that C is wrong because it tries to assign a two-dimensional array where a one-dimensional array is expected. but I don't see a 1-dimensional array anywhere in the code....

Also, D is wrong because it tries to assign a primitive short where a short array is expected, can someone explain this please? Thanks, I'm not quite getting this right now.







Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3036
    
    4

Can you QuoteYourSources so we know where the question came from?

As written, the reason those two options are wrong is because there is no b2 variable in your code. But then again, your code can't compile because you define the variable named b multiple times.


Steve
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9950
    
    6

one technicality...There is no such thing as a two dimensional array in java. There are only one dimensional arrays, but those can hold arrays, which can hold arrays, which can...and so on.


Never ascribe to malice that which can be adequately explained by stupidity.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32704
    
    4
So you should be able to work out whether those arrays are the right type to fit there. Remember the types are arrayOfSomething, arrayOfArraysOfSomething, arrayOfArraysOfArraysOfSomething, etc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about One-Dimensional and Two-Dimensional Arrays
 
Similar Threads
Reg :- Java Multi Dimension Array
Array Reference Assignments
Sierra and Bates Master Exam Question Question
Multi dimansional Array,Master Exam
Master Exam Array question