This content has been marked as final. Show 3 replies
I think it's:
It's pretty rare to refer to a non-static nested class anywher but from within a method or constructor of the enclosing class, where an OuterClass.this is present (and often implicit).
c1.MyInnerClass i1 = c1.new MyOuterClass.MyInnerClass();
See the 2 commented lines near the end of code. They are written in an attempt to see output from the constructor of inner class. Both give error.
How/when can I see the constructor of inner class executed?
How can I call PrintName() method from inner class?
What is exactly wrong with statements in case 1 and case 2 ?
You haven't created an instance of the inner class. So there is no instance to call the methods on.
Modify your code to create an instance of the inner class. When you do the constructor will print out the message.
Then you can call the PrintName method on that instance.
Yes. This worked
MyOuterClass.MyInnerClass i1 = c1.new MyInnerClass();