File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

sarga mockexam

madhuri vl
Ranch Hand

Joined: Jan 17, 2001
Posts: 86
Hi,
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.


madhuri.
Pat Barrett
Ranch Hand

Joined: Jan 03, 2001
Posts: 63
Hello,
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
Hi,
You are right. I totally forgot about post incrementing . Thank you very much for reminding me about That.
Madhuri.
 
jQuery in Action, 2nd edition
 
subject: sarga mockexam