| 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: 32599
|
|
|
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: 16680
|
|
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: 4722
|
|
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?
|
 |
Kemal Sokolovic
Bartender
Joined: Jun 19, 2010
Posts: 792
|
|
|
Abhijit Durge please UseCodeTags and format your code accordingly.
|
The quieter you are, the more you are able to hear.
|
 |
 |
|
|
subject: How to extend inner class
|
|
|