File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Soft Skills this week in the Jobs Discussion 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: 24187
    
  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: 24187
    
  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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Anonymous Class (interface & extends)