Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • 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: 10763
148
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: 10763
148
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
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!