In the following code snippet, presumably it appears that it should issue some compilation error but it doesn\'t:
class Outer {
public static class Inner {
Actually the class name is Outer$Inner.
Inner classes are essentially a hack introduced in Java 1.1. The JVM doesn't actually have any concept of an inner class, and so the compiler has to bodge it. The compiler generates class B
"outside" of class A
, but in the same package, and then adds synthetic accessors/constructors to it to allow A
to get access to it.
Checkout the following post:
Java inner class visibility puzzle