/*If the block containing local class declaration is defined in a static context (i.e. a static method or a static initializer) , then the local class is implicitly static.
A local class cannot be specified with the keyword static.
We can't use this or super keywords in a static context.*/
class Base
{
protected int i=10;
}
class TopLevel
{
static void staticmethod()
{
class StaticLocal extends Base
{
public void print()
{
System.out.println(i);
System.out.println(this.i);
System.out.println(super.i);
}
}//staticlocal
(new StaticLocal()).print();
}//static method
public static void main(
String args[])
{
staticmethod();
}
}//TopLevel
Output:
10
10
10
In the above program StaticLocal class is defined in static context(static method), but S.o.p(this.i), S.o.p.(super.i) statements are not giving any compilation error.
Can any one of you explain me the reason?
Thanx in advance
Naresh