We cant create object without method implementations. Anonymous inner classes allow you to do the following.
interface TestA { public void myMethod() ; } TestA myIntfObj = new TestA() { public void myMethod() { } }; myIntfObj.myMethod();
object gets instantiated that implements the interface.you are converting the interface to an inner class, which you haven’t given a name to (hence anonymous). You have to implement all the interface’s methods, then you have a class, then you create an object from it all in one statement.
Recommended Article
Technically each class has a name, although for anonymous classes that name is not known at compile time. You can see those classes in the same folder as your other class files.