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

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi!
How can an anonymous inner class inplement an interface and extend a non-final class??
Thank you in advance.
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Jordi
When you define an annonymous class that class has no name, it is defined and declared at the same palce, usually in a method. Because it doesn't have a name you can't use the normal extends or implements keywords. So you can only do one or the other, extend another class or implement an interface. Of course you could always extend a class that already implements the interface. All you do is use the new operator with the name of the class or interface you are extending or implementing.
Here is an example of an inner class that implements ActionListener.

hope that helps a little
------------------
Dave
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Dave Vick (edited August 31, 2001).]
[This message has been edited by Dave Vick (edited August 31, 2001).]


Dave
Asma Zafar
Ranch Hand

Joined: May 11, 2001
Posts: 49
In an anonymous calss, you can either extend a non final class or implement and inteface but not both at the same time.
------------------
Asma Zafar,
Sun Certified Programmer for Java2 Platform


Asma Zafar,<BR>Sun Certified Programmer for Java2 Platform
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Anonymous Inner Class