When I compile the above program, It shows compilation error testing1.java:16: non-static variable this cannot be referenced from a static context l.add(new Inner("I")); ^ testing1.java:17: non-static variable this cannot be referenced from a static context l.add(new Inner("AM"));

even though I have tried to create the inner class directly? I know that non static references cannot be referenced from a static context. I am bit confused when it comes to an inner class. Please help me out.

even though I have tried to create the inner class directly? I know that non static references cannot be referenced from a static context. I am bit confused when it comes to an inner class. Please help me out.

It compiles because you are creating Inner's by an instance method of testing1, so you already have a reference of testing1, this.

Ramesh, what Raphael explained is correct ... you will access the method meth() with an instance of the testing1 i.e testing1 te = new testing1(); te.meth(); so inside meth() you will always have this reference. But thats not the case for static method! & the inner class(not a toplevel class) always requires the outer class refernce!