This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Mock Exam Errata and the fly likes sarga mockexam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "sarga mockexam" Watch "sarga mockexam" New topic

sarga mockexam

madhuri vl
Ranch Hand

Joined: Jan 17, 2001
Posts: 86
26) A sample question provided by Sun
Which correctly create an array of five empty Strings?
A.String a [] = new String [5];
for (int i = 0; i < 5; a[i++] = "");
B.String a [] = {"", "", "", "", ""};
C.String a [5];
D.String [5] a;
E.String [] a = new String [5];
for (int i = 0; i < 5; a[i++] = null);
According to me the ans is only b but it is given both a and b.
in optA for (int i=0; i<5; a[i++]="") means it is omitting the zeroth element and thus returns only 4 elements?
Can anybody explain???
Thank you.

Pat Barrett
Ranch Hand

Joined: Jan 03, 2001
Posts: 63
i++ is in post-fix notation. What this means is that the value, in this case i, will be evaluated in its current condition, and then incremented by 1. Since i is initially 0, the first a[i++] will initialize the 0th element of the array.
Hope this helps,
Pat B.
madhuri vl
Ranch Hand

Joined: Jan 17, 2001
Posts: 86
You are right. I totally forgot about post incrementing . Thank you very much for reminding me about That.
Have you checked out Aspose?
subject: sarga mockexam
It's not a secret anymore!