This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inner Classes" Watch "Inner Classes" New topic
Author

Inner Classes

Deepali Pate
Ranch Hand

Joined: Mar 20, 2002
Posts: 114
[/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() {}
Amir Ghahrai
Ranch Hand

Joined: Jun 19, 2002
Posts: 110
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).


Amir
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner Classes
 
Similar Threads
Regarding Inheritance
Inner class
Questions on innerclass and interface
Question about Inner class
Inner Classes