This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Anonymous Inner Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Anonymous Inner Classes" Watch "Anonymous Inner Classes" New topic

Anonymous Inner Classes

Mark Beavis
Ranch Hand

Joined: Apr 07, 2005
Posts: 43
Hi all:

This question is true or false:

"An instance of an Anonymous inner class can only be created in it's outer class."

I picked "true" - but the answer turns out to be "false".

Can anyone explain why?

Ann Sebastian
Ranch Hand

Joined: Sep 21, 2005
Posts: 37
I think the catch is only
Anonymous inner classes can be created from outside the outer class too.
Assuming OuterClass is public

Innerclass inner = new OuterClass().new InnerClass()...
marc weber

Joined: Aug 31, 2004
Posts: 11343

Recall that an "inner" class is a nested class that is not static.


So I would say that an instance of an anonymous inner class can only be created within an instance of its enclosing class. But an instance of an anonymous nested class does not necessarily require an instance of its enclosing class...

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: Anonymous Inner Classes
jQuery in Action, 3rd edition