• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array declaration question on K&B OCA Exam1 CD

 
Harsha Pherwani
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving my question to the correct forum -


Hi,

I am going through the OCA Exam from the CD included with Kathy and Bates's OCA / OCP Java SE 7 Study guide.





This question has me confused - A is one of the valid answers but I believe option B is valid too, apparently it isnt. I am unable to figure out why! (I think its probably something very simple that I am unable to see - maybe its not a curly brace?).

Thanks in advance!
Harsha


 
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
Harsha Pherwani wrote:This question has me confused - A is one of the valid answers but I believe option B is valid too, apparently it isnt. I am unable to figure out why! (I think its probably something very simple that I am unable to see - maybe its not a curly brace?).

You are correct about the code snippet you have posted: both array declarations and initializations will declare an array and initialize it with four members. But your option B is different from the option B in the K&B7 OCA Exam 1 question. So if you look very carefully to this option, you'll notice that option B looks likeIf you want to use the shortcut syntax to create and initialize an array, you'll must use curly braces ({}) and not parantheses (()) because that would result in a compiler error. And that's why option B is not a correct answer!

Hope it helps!
Kind regards,
Roel
 
Harsha Pherwani
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah I thought it was something like that, but I just couldn't see the round brace, it seemed like a curly brace to me!

thanks!
Harsha
 
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
Harsha Pherwani wrote:Ah I thought it was something like that, but I just couldn't see the round brace, it seemed like a curly brace to me!

Please note you need a great eye for detail on the actual exam, because you could expect to encounter similar questions on the actual exam
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic