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 like
If 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