This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Anonymous inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Anonymous inner class" Watch "Anonymous inner class" New topic
Author

Anonymous inner class

Sue Pillai
Ranch Hand

Joined: Nov 04, 2004
Posts: 89
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?


Sue

SCJP 1.2
SCWCD 1.4
SCBCD 5.0
Horatio Westock
Ranch Hand

Joined: Feb 23, 2005
Posts: 221
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

Joined: Nov 04, 2004
Posts: 89
Thanks. sorry I didn't put the question right. I meant the latter. That was a good article. Thanks again.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Anonymous inner class