• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Inheriting a Regular Abstract Inner Class

 
Ranch Hand
Posts: 358
Firefox Browser Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

[ September 14, 2007: Message edited by: Faisal Pasha ]
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like this, for example:

Or, another example:
 
Faisal Ahmad
Ranch Hand
Posts: 358
Firefox Browser Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jesper! Could you please look into this code:

Thanks for your help.
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, let's look at these one at a time. First this one:

Instances of inner classes have an associated enclosing object, which is an instance of the enclosing class. However, Outer2 is a top-level class, so it doesn't have an enclosing class. So there also can't be an enclosing object, which is necessary for Inner1, because it's an inner class.

So this doesn't work: you can't subclass an inner class with a top-level class.

The second problem:

I checked this again, but this also does not work! So my second example was wrong.

The enclosing instance of an instance of Outer1.Inner1 must ofcourse be an Outer1 object. Class InnerTest1 isn't related (via inheritance) to Outer1, so this doesn't work. If you make InnerTest1 extend Outer1, then it works:

You can find all the details about inner classes in section 8.1.3 of The Java Language Specification.
[ September 14, 2007: Message edited by: Jesper Young ]
 
Faisal Ahmad
Ranch Hand
Posts: 358
Firefox Browser Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Jesper!
reply
    Bookmark Topic Watch Topic
  • New Topic