This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Marcus Exam#2 Q54 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Marcus Exam#2 Q54" Watch "Marcus Exam#2 Q54" New topic
Author

Marcus Exam#2 Q54

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Given the following class definition, which of the following statements would be legal after the comment //Here

The answer is 1), 4)
How will this compile since int iam is not initialized?

[This message has been edited by maha anna (edited April 01, 2000).]
Jesper Ottosson
Ranch Hand

Joined: Mar 21, 2000
Posts: 51
it wouldn't, that's why the answer doesn't include alternative 3
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
The answer 3) would not be correct even if int iam is initialized. The local variable has to be final in order to be accessed by the inner class. My question is whether this question should be in the "errata"?
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Howard,
A local var inside a method / any block of code / constructor need not to be initialized during declaration itself. The compiler will complain when you access it's value before initializing it. Try to put a System.out.println(iOther); statement in this method before initializing the var. Now the compiler WILL shout.
regds
maha anna
 
jQuery in Action, 2nd edition
 
subject: Marcus Exam#2 Q54