• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt about 3D array, Chapter 3, page 126 (Java OCA 8 Programmer I Study Guide, Sybex)

 
Patrick Nodder
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe there is an error on page 126 (Chapter 3). On the last line an extra set of brackets is needed to make space a 3D array.

(This post originated in the K&B7 errata thread)
 
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
Hi Patrick Nodder,

First of all, a warm welcome to CodeRanch!

Patrick Nodder wrote:I believe there is an error on page 126 (Chapter 3). On the last line an extra set of brackets is needed to make space a 3D array.

You are incorrect! The study guide is spot-on and space is definitely a 3D array, but I agree the statement is a bit tricky and misleading. That's why you should never use this kind of statements in a real software product.

The statement from the study guideis equivalent toAs you can see the brackets with the type apply to both variables, but the brackets with the variable name only apply to the corresponding variable. So using this confusing code style you can define arrays with a different dimension in the same statement. And to really illustrate (and proof) space is really a 3D-array, you can try to initialize this array using the following codeOnly line3 successfully compiles; line1 and line2 will give a compiler error because the dimension at the right-hand side does not match with the actual dimension of the space array (which is 3).

Hope it helps!
Kind regards,
Roel

PS. You have posted your errata item in the errata thread of the K&B7 study guide. This is a study guide for the OCAJP7 certification exam and thus different than the study guide you are currently reading, which is for the OCAJP8 certification exam. If you spot another (possible) errata item, you can simply create a new topic in this forum (instead of posting a reply in the K&B7 errata thread).
 
Patrick Nodder
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the explanation Roel- that helps a lot. Actually I should have paid more attention to the book-on page 126 it hints at this on the line above which declares the 2D array vars3[].

Cheers
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic