I know that method-inner classes do not have any access modifiers (like other local variables). But I see that the members of the inner class can have access modifiers. However, it appears these are ignored.
For example, the code below produces "A\nB". When I would expect there would be a compiler error on line 16.
Also, another question, how would i then be able to use the object returned by "getClassy" (i.e. call "doB()" from Object a) ?
[ December 14, 2008: Message edited by: Clay Chow ] [ December 14, 2008: Message edited by: Clay Chow ]
First, regarding the (lack of) a compilation error: every member of every inner class defined within a class is accessible to all code in that outer class's scope. Because the inner class is a member of the outer class, its "private" declarations are treated just like the private declarations of the outer class with regard to access from anywhere within that outer class.
Second, how would you call "doB()" on that Object? Well, you could call it using the reflection API, but that would be a terrible and pointless design. More commonly, the class "Do" would implement an interface, or extend an abstract class, and the clients of that class could call the methods of the interface or abstract class: