• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

How to extend inner class

 
Ranch Hand
Posts: 57
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone !!

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

Thanks
 
Marshal
Posts: 80145
418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, please see if the code snippet helps




PS: InnerExtended needs to be inside a class extending Parent. In this case Child.
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Abhijit Durge please UseCodeTags and format your code accordingly.
 
It's feeding time! Give me the food you were going to give to this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic