This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line!
See this thread for details.
  • 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Inner Classes

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Following code gives compile time error on line 6
InheritInner.java:6: an enclosing instance that contains Outer.Inner is required.

Can anyone explain me the cause of the error and how to rectify it. Thanks.


 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Outer {

class Inner { }
}

class InheritInner extends Outer.Inner {

InheritInner() {new Outer().super();}

public static void main(String[ ] args) {

Outer o = new Outer( );

InheritInner ii = new InheritInner( );
}
}

OR

class InheritInner extends Outer.Inner {

InheritInner(Outer o) {o.super();}

public static void main(String[ ] args) {

Outer o = new Outer();

InheritInner ii = new InheritInner(o);
}
}
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here we are trying to create a subclass for an Inner class. The complier obviously complains here because--->> When we try to create an object for "InheritInner", then it has to initialize "InheritInner" class AND all of its superclasses in the hierarchy!

Here in our case, the complier cant initialize a member (i.e the inner class "Inner" which is actually a part of another class i.e "Outer")

Hence the error!
 
Sharn Arora
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Girish & Balaji
 
What's a year in metric? Do you know this metric stuff tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic