This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

inner classes see everything?  RSS feed

 
Eduardo Pereira
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
question seen in this site:
(#232) TRUE or FALSE: a
non-static inner class always
has free access to ALL member
data of its enclosing (outer)
class.
Answer: TRUE
An inner class has a special
relationship and can see even private
member data of the outer class.
What if it is an anonymous inner class defined inside a method?? As far as I know those classes can only refer to final member variables of the outer class (wether public or private).
Am I right, or did I misunderstand the question?
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Study forum.
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eduardo, you're confusing "member" variables and "local" variables.
Member variables belong to the enclosing class, and are always available freely to the inner class.
Local variables usually cease to exist when the method in which they are defined exists; however, by marking these local variables final (including paramater variables, which are also local) you can use them in your inner class. An inner class may not use any non-final local variables.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!