Friday, February 27, 2009

sample code method local inner class with variables



package innerclass;

public class MethodOuter2 {
static int x=10;
public static void m1()
{
int y=20;
class MethodInner2
{
void show()
{
System.out.println(x); // 10
System.out.println(y); // Compile time error ( If y is final no error)
}
}
MethodInner2 in=new MethodInner2();
in.show();
}
public static void main(String ar[])
{
MethodOuter2 o=new MethodOuter2();
o.m1();
}
}





0 comments:

Post a Comment