InnerThis program
The InnerThis
program illustrates the use of this
in inner classes.
It creates an instance of the InnerThis
class, which creates an instance of the Inner
class.
The Inner
class is an inner class of InnerThis
.
The this.i
expression refers to the i
variable of Inner
.
The InnerThis.this.i expression refers to the i
variable of InnerThis
.
The output of the program is:
2
1
The InnerThis program
class InnerThis{
int i = 1;
public static void main(String[] args){
new InnerThis();
}
InnerThis(){
new Inner();
}
class Inner {
int i = 2;
Inner(){
System.out.println(this.i);
System.out.println(InnerThis.this.i);
}
}
}