aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Anonymous Inner class 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 "Anonymous Inner class" Watch "Anonymous Inner class" New topic
Author

Anonymous Inner class

Suguna Gollapally
Ranch Hand

Joined: Oct 31, 2006
Posts: 37
Which of the following is true ??

1.An anonymous inner class may be declared as final

2.An anonymous inner class may be declared as private

3.An anonymous inner class can implement multiple interfaces

4.An anonymous inner class can access final variables in any enclosing scope
5.Construction of an instance of a static inner class requires an instance of the enclosing outer class

Here option 3 and 5 are false because static inner class doesnt require outer class instance and Anonymous inner class extends only one class or implements one interface..

Anonymous inner classes are implicitly final right..

Then what about the other??
jimmy halim
Greenhorn

Joined: Nov 28, 2006
Posts: 15

1.An anonymous inner class may be declared as final
2.An anonymous inner class may be declared as private


I don't think anonymous inner class has modifier beside what inherited from it parent (the inner-class). Modifier used to interact (is-a or has-a) with other classes.
But anonymous class only used once, it has no name.

And I don't have any idea where we can put a modifier in anonymous class



We can only extend 1 class or interface in anonymous class


4.An anonymous inner class can access final variables in any enclosing scope

Like other inner class, it can access any outer class method & property. And final local variable.


5.Construction of an instance of a static inner class requires an instance of the enclosing outer class

because it's static we don't need outer class' instance

CMIIW


Knowledge is power<br />My Blog : <a href="http://jimmod.blogspot.com/" target="_blank" rel="nofollow">http://jimmod.blogspot.com/</a>
Abdul Rehman
Ranch Hand

Joined: Nov 07, 2006
Posts: 65
Originally posted by jimmy halim:
I don't think anonymous inner class has modifier beside what inherited from it parent (the inner-class).

In the JLS, Section 15.9.5, it is written:

An anonymous class is never abstract (�8.1.1.1). An anonymous class is always an inner class (�8.1.3); it is never static (�8.1.1, �8.5.2). An anonymous class is always implicitly final (�8.1.1.2).

Yours,
Abdul Rehman.


SCJP 5.0 (100%)
Mat Austin
Greenhorn

Joined: Dec 01, 2006
Posts: 7
Does anyone know...

In terms of the exam, when it states
"1.An anonymous inner class may be declared as final "
is the answer going to be false, since you cannot apply modifiers to an anonymous inner class. Or will it be true, becuase anonymous inner classes are implicitly final?

It seems that you could get this question wrong even if you understood anonymous classes?

Cheers
Matt
jimmy halim
Greenhorn

Joined: Nov 28, 2006
Posts: 15

Does anyone know...

In terms of the exam, when it states
"1.An anonymous inner class may be declared as final "
is the answer going to be false, since you cannot apply modifiers to an anonymous inner class. Or will it be true, because anonymous inner classes are implicitly final?

It seems that you could get this question wrong even if you understood anonymous classes?


Yes I also wondering what will be the right answer, it's ambiguous
At first sight I though the question is about declaring explicitly.

Thanks alot to Abdul Rehman for the JLS info

Maybe the questions should be clearer with stating if it's explicitly or not
 
 
subject: Anonymous Inner class