aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Marcus Exam#2 Q54" Watch "Marcus Exam#2 Q54" New topic

Marcus Exam#2 Q54

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
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
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.
maha anna
Don't get me started about those stupid light bulbs.
subject: Marcus Exam#2 Q54
Similar Threads
Local classes
Question on Local classes .
inner class access variables