Styrow.dev
Question 122 of 247
Java Topic: General medium

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

Question

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

Answer

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 are created will be created. Though a separate inner class file is generated, the inner class file is not accessible in the usual way.

EnclosingOuter.class EnclosingOuter$Inner.class