• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

inner classes see everything?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to the Study forum.
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic