Re: Question about extending inner class



Hi Vahan,

Unless an inner class is defined as static then it can not be created
outside of the context of an enclosing class instance. I'm looking at
the syntax of your example and it does look strange. Remember an inner
class will have access to its enclosing classes methods and members so
it makes perfect sense that you can not create an inner class outside
the context of an enclosing class instance. Also consider this strange
looking syntax. Hope that sheds some light.

public class Outer{

public class Inner{
}

public static void main(String[] args){
Outer.Inner inner = new Outer().new Inner();
}

}

Cheers,

Dan Andrews

- - - - - - - - - - - - - - - - - - - - - - - -
Ansir Development Limited www.ansir.ca
- - - - - - - - - - - - - - - - - - - - - - - -


vahan wrote:
We have some simple code(Bruce Eckel's book):

class WithInner {
class Inner {}
}

public class InheritInner
extends WithInner.Inner {
//! InheritInner() {} //DON' T compile

InheritInner(WithInner wi) {
wi.super(); // is OK
}
public static void main(String[] args) {
WithInner wi = new WithInner();
InheritInner ii = new InheritInner(wi);
}
}

question is following :
Why does it call "wi.super();", as I understand WithInner's super
class constructor?
Thanks

.



Relevant Pages

  • Protected inner classes and inheritance
    ... a top-level class with a protected inner class. ... I have a second-level class ... in a different package that extends the top-level class. ... public class SecondLevel extends TopLevel ...
    (comp.lang.java.programmer)
  • Re: "Private" nested classes
    ... Wouldn't making the inner constructor private solved the problem though? ... "Etienne Boucher" wrote: ... > outside the outter class. ... > public class Outter ...
    (microsoft.public.dotnet.languages.csharp)
  • "Private" nested classes
    ... Nested classes are usualy objects made to only live in their parent object ... public class Outter ... still being able to access the members of Inner. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Question about extending inner class
    ... Unless an inner class is defined as static then it can not be created ... outside of the context of an enclosing class instance. ... public class Outer{ ... public static void main{ ...
    (comp.lang.java.programmer)
  • Re: Question about extending inner class
    ... Unless an inner class is defined as static then it can not be created ... outside of the context of an enclosing class instance. ... public class Outer{ ... public static void main{ ...
    (comp.lang.java.programmer)