Friday, February 27, 2009

sample code to use this keyword in inner class

package innerclass;

public class Outerclass {
int x=10;
class Inner
{
int x=50;
public void m1()
{
System.out.println(x); // 50
System.out.println(this.x); // 50
System.out.println(Outerclass.this.x); // 10
}
}
public static void main(String ar[])
{
Outerclass o=new Outerclass();
Outerclass.Inner in=o.new Inner(); //Outer.Inner in=new Outer().new Inner();
in.m1();
}
}


1 comments:

Anonymous said...

Excellent tutorial for Core java

Post a Comment