| Author |
Extending a second Inner Class
|
Milton Ochoa
Ranch Hand
Joined: Oct 23, 2007
Posts: 336
|
|
Hi everyone, Today I was studying about Inner Class, and I trying a few combinations with the classes. Then a found this: this is the output that the compiler shows: This is very rare, why the second inner class cannot extend from the first class? And if someone can explain me the compile error. Thank you
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32827
|
|
|
What sort of constructor do you have in the superclass? Are you required to call in with a super(x, y, z); statement?
|
 |
Milton Ochoa
Ranch Hand
Joined: Oct 23, 2007
Posts: 336
|
|
Hi Campbell. I dont understand what are you question me! can you explain more please!
|
 |
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
|
|
The inner inner class implicitly has a reference to an instance of the inner and outer class. Also, the inner inner class [default] constructor needs to call the inner class [default] constructor, as its superclass constructor. Somehow, in a way that I haven't exactly worked out, the compiler needs to access the instance of the inner class before the inner class constructor has been called, as the superclass constructor. To be honest, I don't think there is a huge amount to be gained by deep analysis of what is going on here (which is why I haven't bothered!). I don't believe there would ever be a good reason to have an inner class that extends its enclosing class. So just Don't Do That Then.
|
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
|
 |
Brian Cole
Author
Ranch Hand
Joined: Sep 20, 2005
Posts: 852
|
|
Note that if either of the nested classes is declared to be static, or either is declared with a different superclass, then it compiles without error. But where's the fun in that. It will also compile if we use a qualified superclass constructor invocation: Or we could write it this way: I mostly have a handle on why the original doesn't compile, but I'm having trouble putting it in words. (Which means I must not completely understand it.) (cf. JLS �8.1.3) [ January 31, 2008: Message edited by: Brian Cole ]
|
bitguru blog
|
 |
 |
|
|
subject: Extending a second Inner Class
|
|
|