This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Marcus Exam#2 Q54

 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it wouldn't, that's why the answer doesn't include alternative 3
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1467
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic