Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Anonymous inner class

 
Sue Pillai
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I extend and implement an anonymous inner class? What is the syntax if say Super is the super class and MyInt is the interface I want to implement?
 
Horatio Westock
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sue Pillai:
Can I extend and implement an anonymous inner class? What is the syntax if say Super is the super class and MyInt is the interface I want to implement?


If you mean, "Can I extend an anonymous inner class?". Then the answer is no. They are implicitly final.

If you mean, "Can I write an anonymous inner class that extends a class and implements an interface"? If so, then no. You can write an anonymous inner class that either extends a class or implements an interface.

To implement an inteface, you would use:



To extend a class you would use:




Hope this helps, if you have more questions, just ask.

You may also find this article helpful:

developer.com: SJCP Exam Preparation
 
Sue Pillai
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. sorry I didn't put the question right. I meant the latter. That was a good article. Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic