• 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

Inner classes

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I sound ignorant but can't help I an confused with various inner classes and their accesibility here is my question
Can local static inner classes access final variable in the enclosing context(say method) and the outer class in which this method is declared.I know they can access all ststic members.and I think nonstatic inner classes can acess every member in the enclosing context including final members but can they access static members.
Please send me some information on this.
Thanks
Leela
 
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
Leela,
I'm moving this to the SCJP Forum.
Moreover, I'd like you to read the Javaranch Naming Policy and register again.
Thank you for your cooperation.
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Leela:
Can local static inner classes ...


There is no such thing as a local static inner class. A local inner class cannot be static. Please clarify your question.
 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check this out
http://www.javaranch.com/campfire/StoryInner.jsp
It gives you a great understanding of scope, accessibility and everything else you always wanted to know about inner classes.
 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marilyn deQueiroz:

There is no such thing as a local static inner class. A local inner class cannot be static. Please clarify your question.


Um. . .I don't think this is right. A local class in a static block is considered to be static - at least that's what Khalid's book says on page 224 and on page 225 in Table 7.1. - unless I'm reading it wrong.
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have not read Khalid's book, and I will not dispute his definition. But RHE says "Inner classes defined local to a block may not be static". Obviously the definition of a "local static inner class" as defined by these two authors is different.

Therefore, I asked Leela to clarify his/her question.
 
Jim Bedenbaugh
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marilyn deQueiroz:
I have not read Khalid's book, and I will not dispute his definition. But RHE says "Inner classes defined local to a block may not be static". Obviously the definition of a "local static inner class" as defined by these two authors is different.

Therefore, I asked Leela to clarify his/her question.


I have both books and to be honest, I often find these kinds of disagreements. We both know you cannot explicitly declare a local inner class to be static (in preparation for the test, I have coded all kinds of variations to make sure I "own" the knowledge), so I will for sure say that you cannot modify a local inner class with the static keyword, but I will grant that it can be static within the context of a static block. I looked in the JLS for some clarification, but can't find anything. Any thoughts?
 
it's a teeny, tiny, wafer thin ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic