Two Laptop Bag
The moose likes Beginning Java and the fly likes extending an inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "extending an inner class" Watch "extending an inner class" New topic

extending an inner class

lyko saha

Joined: Aug 21, 2004
Posts: 5
Is it possible to extend a non-static inner class outside of its outer class? For example:

class Outer
{class Inner {}
public class A extends Outer.Inner

If I compile class A, I get an error:
No enclosing instance of class B is in scope; cannot create a default constructor for class A.
Nick George
Ranch Hand

Joined: Apr 04, 2004
Posts: 815
I would say that regardless of whether it is possible or not, which I truly don't know the answer to, you should never need to. The point of an non-static inner class is that it belogs within the outer class. Period. If you want to make an extension of the outer class that has an inner class that extends the inner class of the super class, this is perfectly doable, however convoluted.


I've heard it takes forever to grow a woman from the ground
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608

Tony Morris
Java Q&A (FAQ, Trivia)
I agree. Here's the link:
subject: extending an inner class
It's not a secret anymore!