Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding Inheritance

 
Sujittt Tripathyrr
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why this code snippet gives error :

1. class Outer {
2. class Inner { }
3. }
4.
5. public class InheritInner extends Outer.Inner {
6. InheritInner () { }
7.
8. public static void main(String [ ] args) {
9. Outer o = new Outer( ) ;
10. InheritInner ii = new InheritInner( ) ;
11. }


Thanks in Advance
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This thread.
 
Neelesh Bodas
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The issue is that the InheritInner constructor was not able to call the superclass's constructor, since it could not find an instance of outer class to associate to.

Making the inner class static is also an alternative solution.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic