hi...I tried to create a simple MyOuter class which holds an inner class called MyInner. As expected, two .class files where created after compilation as shown below:-
Can Someone please explain me as to why no constructor was created for MyOuter class as the compiler is supposed to insert it by default.
Secondly, what is the meaning of MyOuter paramMyOuter argument in MyOuter$MyInner constructor and how it helps.Please explain me the complete flow.
When you create an inner class MyInner inside MyOuter, the Java compiler will indeed generate a class file named MyOuter$MyInner.class for the inner class. By the way, how did you get the output in the bottom half of your code - did you run javap or a similar tool?
I guess the compiler is smart enough to see that the constructor of your class MyInner contains no code and therefore you don't see it when you decompile the class. Try adding some code in there (for example just a simple System.out.println("hello");) and then you'll see the constructor when you decompile it.
About paramMyOuter: Each instance of a non-static inner class has a reference to the instance of the outer class that it was created in. The paramMyOuter is how the compiler passes this internally to the inner class. When you make class MyInner static, I think this will disappear.
(I've closed the copy in the other forum, let's answer the question in this forum).