• 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

Java Rule Round-up Question 136

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, folks!
The following question is - in my humble opinion - not precise:
(#136)TRUE or FALSE: An
inner class has free access
to private member data of the
outer class.
Answer: TRUE
Given a static inner class X and a non-static private member data Y located in the outer class of X, X will not be able to access Y.
Therefore, question 136 should start with 'A non-static inner class has free access ...'.
Best regards,
Seraphin
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seraphin
Actually, according to the
JLS Section 8.1.2a static nested class is not an inner class.

An inner class is a nested class that is not explicitly or implicitly declared static.


hope that helps
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is still a loophole here - technically if a local class is declared inside a static method, static initializer, or static variable initialization expression, it is considered an inner class declared in a non-static context. Such a class does not have access to an enclsing instance, since there is none - and thus no member variables of the enclosing class can be accessed. But modifying the question wording to account for this case just tends to confuse people more than it helps, as it's a rather obscure example.
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jim Yingst:
...it is considered an inner class declared in a non-static context. Such a class does not have access to an enclsing instance, since there is none - and thus no member variables of the enclosing class can be accessed.


Did you mean ..."an inner class declared in a static context?"
Rob
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, something like that.
 
No, tomorrow we rule the world! With this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic