This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
output... outer variable: hi1 inside the method_class: hi3 final variable: hi2 value of s: hi4
Correct me if i am wrong.. [ April 29, 2008: Message edited by: Dinesh Tahiliani ]
Joined: Mar 24, 2008
If it is another variable then it is ok to access that variable. But if the variable has same name as of the inner class instance variable then how to access that method variable from inside the inner class method.
you can't access it. it is double shadowed. there is no keyword such as this, that could refer to local variable that you want to access. here is simplified example:
you can access s at line 2 only with a call that you made in line 5, but that is impossible since line 2 is shadowed by variables defined in line 4, and line 3. also without call this.s you couldn't access line 3 s because it is shadowed by line 4. so if you want to access line 2 variable it must be accessible i.e. not shadowed or as Dinesh did, you have to rename it. and please use code tags...