Is it possible to have an inner class in an interface and create an instance of it? I tried the code below, but I am getting a compiler error at line 20: qualified new of static class. I had to create the anonymous class due to the obvious reason that an interface cannot be instantiated.
This is a very misleading bit of source code, as a matter of fact
An interface can't actually define an inner class, eventhough it certainly appear to in your code sample.
However what you're code actually defines is this:
The public, static and final modifiers in an interface are implicit. What you have here then is not actuall an inner class, but rather a static nested class.
Eventhough a static nested class is referred to via the enclosing class name, an instance of it is not associated with an instance of the enclosing class, and exists separately.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Joined: Jul 20, 2012
Thanks a lot for your explanation. That was helpful!