Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic