It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes a question for Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "a question for "For loop"." Watch "a question for "For loop"." New topic

a question for "For loop".

sura watthana
Ranch Hand

Joined: Sep 13, 2004
Posts: 77
please look at the question below

which one is the correct answer and what about the rest of the choices?

Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Usually Mock Exams have their answers provided. Where exactly does this question come from?

What happens when you compile each of these expressions?
[ October 18, 2004: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Arnab karmakar
Ranch Hand

Joined: Oct 04, 2004
Posts: 46
Hi sura,

Acording to me only a and d are the coorect answers.

Anand B Raju
Ranch Hand

Joined: Sep 22, 2004
Posts: 172
hello arnab,
i think u have made wrong decision in ur choices.
according to me,

choice a) is wrong because identifier 'j' is declared and initialized in "for" loop after declaring same variable 'j' inside the method before "for" loop.

choice b) is wrong because comparision part of "for" loop doesn't evaluate to a boolean value.

choice c) is correct because it follows all the rules.

choice d) is wrong because variable i is used without initializing it.

choice e) is wrong because the format of "for" loop declaration is only wrong
[ October 18, 2004: Message edited by: Anand B ]

SCJP 1.4<br /><a href="" target="_blank" rel="nofollow">SUN JAVA 4 U</a>- links and resources for SCJP aspirants
I agree. Here's the link:
subject: a question for "For loop".
It's not a secret anymore!