File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How to extend inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to extend inner class" Watch "How to extend inner class" New topic
Author

How to extend inner class

Subhash Pavuskar
Ranch Hand

Joined: Jun 29, 2011
Posts: 57

Hello Everyone !!

Can anyone please explain is that possible to extend inner class if yes then please give me the snippet of code.

Thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37936
    
  22
That question is vague. Is it a private or public inner class? Do you want to extend it inside the class or in another class? Why would you want to? What have ou tried so far?
Abhijit Durge
Greenhorn

Joined: Oct 31, 2012
Posts: 9
Hello, please see if the code snippet helps




PS: InnerExtended needs to be inside a class extending Parent. In this case Child.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18508
    
  40

Abhijit Durge wrote:
PS: InnerExtended needs to be inside a class extending Parent. In this case Child.


And if you don't want the outer classes to have any relationship whatsoever -- except for the inner class inheriting from each other that is -- then you can do something like this...



[EDIT] Just realized that the OP didn't mention that the inner class has to be extended by another inner inner class. Extending the inner class from a top level class is similar...



Hope this helps,
Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7503
    
  18

Abhijit Durge wrote:PS: InnerExtended needs to be inside a class extending Parent. In this case Child.

I see nothing wrong with what you've written (apart from maybe your names). However, to make Inner extendable by ANY class that extends Parent, you should really make it protected, viz:
protected class Inner { ...

However, my question would be: How often do you think you're going to need this information? True inner classes are rare enough, and their use tends to suggest finality, not extension. If it's for the SCJP exam, then good luck with that; but the chances of you ever needing to use it in real life are slim to none (in eleven years of Java programming, I haven't).

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

Abhijit Durge please UseCodeTags and format your code accordingly.


The quieter you are, the more you are able to hear.
 
Don't get me started about those stupid light bulbs.
 
subject: How to extend inner class
 
Similar Threads
Inner class
Annonymous inner class
inner classes
non static inner class
extend inner class