Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

overloading overriding etc

 
Karin Paola Illuminate
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the answer of the following question?
[JavaCertification.com]
What will be the output of the following code?


1. Compilation succeeds, the output is: New value: 1
2. Compilation succeeds, the output is: New value: 0
3. Compilation fails, cannot create a class within the method body foo() at line 4
4. Compilation fails, cannot access the member variable ii from the class Inner at line 6
5. Compilation fails, the constructor from the test class should have been declared as public at line 4

Feedback:
Answer 4 is correct, the member variable should have been declared as final. It is impossible to change the variable ii within the test class.
The class test is called a local class and as such can only access the list of parameters defined in the method or access final fields from the top level class.
You have answered: [ 2 ]
I read somewhere "Local inner classes can access all the variables and methods of the enclosing class, but can only access final local variables and method arguments of the enclosing method." And, therefore answered "2". But, that seems not to be the correct answer.
(BTW. I think the ' in the code is a typo, and I did not pay attention to it.)
[ April 12, 2003: Message edited by: Karin Paola Illuminate ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct, Karin, the code compiles (after changing the single quotes) and gives the result 0.
 
Karin Paola Illuminate
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying.
(I contacted the site owners, and the answer will be changed.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic