| Java FAQ | ||
| JSP FAQ | ||
| Servlet FAQ | ||
XyzWs Java FAQ:
How to use keyword 'this' in an inner class?
Printer-friendly version |
Mail this to a friend
|
Advertisement
|
How to use keyword 'this' in an inner class?According to the 15.8.3 this:
The name The following code outputs
class Outer {
private int a=10;
class Inner {
private int a=20;
public void myMethod() {
System.out.println(this.a);
}
}
}
How could we possibly to access the variable
According to the 15.8.4 Qualified this, the syntax of In all classes, each current instance can be named explicitly or can play an
implicit part when its members are used. Any current instance can be referred
to by explicitly qualifying the keyword
class Outer {
private int a=10;
class Inner {
private int a=20;
public void myMethod() {
System.out.println(Outer.this.a);
}
}
}
ReferencesHow do inner classes affect the idea ofthis in Java code?
|