Ankit is right. If you want to be overly technical, you could say that all classes can (and indeed must) have constructors. When you don't explicitly declare a constructor, the class obtains the default constructor provided by the compiler. In the case of an anonymous inner class, it is clear why you can't have an explicitly defined constructor, because the constructor must have the same name as the class, but...what's the name of an anonymous class? However, the anonymous inner class must get a default constructor that simply calls the super() constructor of the class extended by the anonymous class (if the anonymous class extends a class.) If the anonymous class instead implements an interface, and given that interfaces do not have constructors, the anonymous class will get a default constructor that doesn't do anything.
All code in my posts, unless a source is explicitly mentioned, is my own.
I'm having a problem with instantiating an innner class from a static context...Could you tell me where I'm going wrong??
Joined: Oct 16, 2008
Inner4 is method local class, so just instantiate is as line1.
Joined: Dec 16, 2008
Inner4 looks like a method-local inner class. You need to instantiate it the same way that you are instantiating Inner3. The only difference is that since Inner4 is inside a static method, Inner4 won't be able to access any instance members from the enclosing class, just static members.
Edit: What Punit said. He must have submitted his reply while I was writing mine.