File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Inner classes query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Inner classes query" Watch "Inner classes query" New topic
Author

Inner classes query

shyamala vydyam
Greenhorn

Joined: Sep 20, 2010
Posts: 4
Hi All

I have the following classes !!



class Outer{

class InnerA extends Outer{


}

class InnerB extends InnerA{

// I have the following error while creating this inner classes


// No enclosing instance Outer available due to immediate constructor invocation
}

}


Can any one tell me why we cant extend Inner class with another inner class?

Bit confused with this !!

Thanks,
Shyamala
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575



if you want to extend an Innerclass. then you must access with his constructor by enclosing class instance. i.e, some thing like this


hope this helps
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

and Welcome to JavaRanch Shyamala
shyamala vydyam
Greenhorn

Joined: Sep 20, 2010
Posts: 4
Hi Seetharaman Venkatasamy ,


thats great solution but now the concept looks most contradictory where i cant create a simple object...........

new Outer().new InnerB(new Outer());

this is how we can create the object!!

where exactly this concept can be used!!??

new Outer().new InnerB();



Let me know why is this concept & its use in real time?

Thanks,
Shyamala
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

add one no-arg constructor in InnerB
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Inner classes are too difficult for "beginning". Thread moved to another forum.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner classes query