Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Anonymous Inner Class

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
How can an anonymous inner class inplement an interface and extend a non-final class??
Thank you in advance.
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Asma Zafar
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic