• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

nested inner classes

 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
Can a local inner class access and manipulate the class variables (the ones not within the same scope as the nested class or passed to the method enclosing this class)?
Thanks,
Sasikanth
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Local inner class can access all the instance variables of the enclosing class, final variables of the enclosing method and all the variables of the inner class(itself)
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sasikanth Malladi:
Hi!
Can a local inner class access and manipulate the class variables (the ones not within the same scope as the nested class or passed to the method enclosing this class)?
Thanks,
Sasikanth


local class in a static context - i.e. in static method
can access static variables in the enclosing outer class, the accessible static variables in the super class if any, and the final variables in the method
local class in a non-static context - i.e. non-static method
can access static and non-static variables in the enclosing outer class, and accessible static and non-static variables in the super class if any, and the final variables in the method
For good examples read Mughal Chapter 7.

 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You REALLY need to read:
http://www.javaranch.com/campfire/StoryInner.jsp
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic