Author | Topic: inner class question |
sree ranch hand |
posted April 04, 2000 12:36 PM
I found this question in Jaworski's mock exam. Which statement is true about a non-static inner class? a. It must implement an interface. I answered b&e. But the answer given is only e. Could somebody please explain what am i missing here. Thanks.
|
JRoch greenhorn |
posted April 04, 2000 01:12 PM
Hi Sree, If b) was worded more precisely: "It is DIRECTLY accessible to any other classes" then you probably wouldn't have selected it. May be this is what they meant. You probably assumed: See JavaRanch good tutorial on this. JRoch
|
sree ranch hand |
posted April 04, 2000 02:01 PM
Thanks JRoch.
|
maha anna bartender |
posted April 04, 2000 02:52 PM
Sree, Even if you have access to the Outer class from Another class you may or may not have access to the inner class in the Another class. To put it simple, If the inner class is private to the outer class then you CANNOT access it from other classes. See the foll example. If I remove the comment a compiler error will occur. You know which error.
|
Jim Yingst sheriff |
posted April 04, 2000 03:04 PM
Two more things: A "non-static inner class" could also include a local class or an anonymous class (which is a type of local class). These are not accessible outside their scope. Probably Jaworski meant a non-static member class. A member class will not be accessible in outside classes unless it has an appropriate access modifier. So B is not true in general unless the class is public. I'm moving this to Mock Exam Errata. Thanks!
|
| | |