Hello,
I refered K & B book it says
you can�t instantiate the inner class from a static method of the outer
class (because, don�t forget, in static code there is no this reference).
My question is the main method also a static method.
why this following code is not giving compilation error.
Thanks, Raghu.K
class MyOuter {
private int x = 7;
public void makeInner() {
MyInner in = new MyInner();
in.seeOuter();
}
class MyInner {
public void seeOuter() {
System.out.println("Outer x is " + x);
System.out.println("Inner class ref is " + this);
System.out.println("Outer class ref is " + MyOuter.this);
}
}
public static void main (
String[] args) {
MyOuter.MyInner inner = new MyOuter().new MyInner();
inner.seeOuter();
}
}