• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Inner Classes

 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[/code]class Outer {
class Inner { }
}

public class InheritInner extends Outer.Inner{

InheritInner() {}
public static void main(String [ ] args) {
Outer o = new Outer( ) ;
InheritInner ii = new InheritInner( ) ;
}
}
[code]
This program gives the following error. How can we rewrite it such that it gives no compile time error.
InheritInner.java:8: No enclosing instance of class Outer is in scope; cannot create a default constructor for class InheritInner.
InheritInner() {}
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought in order to extend a (non-static) Inner class, you must first create a reference to the outer class, so that you can use the reference to access the inner class. One way round that could be to extend the outer class first, and then extend the inner class inside your class..(confusing).
 
You have to be odd to be #1 - Seuss. An odd little ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic