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