Tuesday, 19 April 2011

If you compile a file containing inner class how many .class files are created and what are all of them accessible in usual way?

 If a inner class enclosed with an outer class is compiled then one .class file for each inner class an a .class file for the outer class is created. e.g.
class EnclosingOuter {
    class Inner{ }
 }
 If you compile the above code with command
% javac EnclosingOuter.java
Two files
EnclosingOuter.class
EnclosingOuter$Inner.class

will be created. Though a separate inner class file is generated, the inner class file is not accessible in the usual way like,
% java EnclosingOuter$Inner

No comments:

Post a Comment