This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Anonymous Class (interface & extends) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Anonymous Class (interface & extends)" Watch "Anonymous Class (interface & extends)" New topic
Author

Anonymous Class (interface & extends)

faisal usmani
Ranch Hand

Joined: Jan 14, 2006
Posts: 139
Hi ,

Can an anonymous class be declared as implementing an interface and
extending a class ?


Thanx in advance
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

No. If you need to do both, then you'll need to use a named class (which could still be an inner class, just not an anonymous one.)


[Jess in Action][AskingGoodQuestions]
faisal usmani
Ranch Hand

Joined: Jan 14, 2006
Posts: 139
Thanx Ernest

But can you give me a little detail why is it not possible ?



-No act of kindness, no matter how small, is ever wasted
regards
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Just because the language specification provides no way to do it. I suppose the logic was that if you need to do anything that complicated, then it's worth creating a class with a name. Anonymous classes are supposed to be tiny one-liners -- anything larger belongs in a named class.
 
wood burning stoves
 
subject: Anonymous Class (interface & extends)
 
Similar Threads
anonymous class
Anonymous inner class doubt
Anonymous Inner Class
Interface trouble
What is an interface?