File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ranch Office and the fly likes Java Rule Round-up Question 136 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » This Site » Ranch Office
Bookmark "Java Rule Round-up Question 136" Watch "Java Rule Round-up Question 136" New topic
Author

Java Rule Round-up Question 136

Seraphin
Greenhorn

Joined: Jan 10, 2002
Posts: 2
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
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
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


Dave
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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.


"I'm not back." - Bill Harding, Twister
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
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


Rob
SCJP 1.4
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Yeah, something like that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Rule Round-up Question 136