This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
The name this.x refers to a variable named x in this instance of the object. It is pretty obvious that if you refer to this in an inner class, it refers to fields or variables defined in the inner class itself.
Joined: Aug 03, 2002
Why the above throws error at the line mentioned but when said class inner extends outer this.a works fine. Reason?
Simply because it cannot inherit x from its superclass because it is private. If you make x accessible using this.x (or just x) in the println will work.
Compile and run this code:
Can you now see what is happening?
Make x private again and compile. Then comment out the line that does not compile and compile and run it again. Can you see the difference? [ October 06, 2006: Message edited by: Barry Gaunt ]