• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

3D array declaration potentially wrong? (Java OCA 8 Programmer I Study Guide, Sybex)

 
Jason Attin
Ranch Hand
Posts: 232
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI guys, I've noticed something on page 126 of the OCA book (1ZO-808).
Under "Creating a multidimensional array" the last line reads:

Now, shouldn't the 3D array declaration be instead?
thanks
 
Jason Attin
Ranch Hand
Posts: 232
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies, just came across this post https://coderanch.com/t/665159/ocajp/certification/array-Chapter-page-Java-OCA, so the declaration is correct.
 
Stephan van Hulst
Bartender
Pie
Posts: 6503
83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Technically, the book is wrong for the simple reason that Java doesn't have multidimensional arrays at all. Java has arrays of arrays. They don't have more than one dimension.

Regardless, I know what you mean, and no: If you declared int[] vars4 [], space[][][], then space would be a '4-dimensional' array.

Tell me, from the code you wrote, what is the type of space?
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:Technically, the book is wrong for the simple reason that Java doesn't have multidimensional arrays at all.

The authors always follow the official exam objectives from Oracle in their study guide. And one of the exam objectives of the OCAJP8 certification exam is "Declare, instantiate, initialize and use multi-dimensional array".
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason Attin wrote:Now, shouldn't the 3D array declaration be instead?

No, it should not. As you already have figured out from reading this topic declaring the space array like that, you'll create a "4D-array" (which is much shorter to type than "an array of an array of an array of an array of int" ). And that's why you should never try to combine array declarations with a different dimension into one statement in real code. Your colleagues will be very grateful
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic