Originally posted by Aparna:
My question is why only one interface?
I guess the doubt arises in your mind because a normal class can implement more than one interface but an anonymous class cannot.
Let me try and answer this question:
The syntax for an anonymous inner class allows us to create on the fly instances of classes/interfaces needed by us.
You can see that with the creation of an implementation of SINGLE interface using anonymous inner class is pretty complex as compared to the other syntax of
java.
Also with the syntax made available for anonymous inner classes(AIC) by java creators, it would become even more complicated to allow an AIC to implement multiple interfaces.
I guess they wanted to keep the unnecessary complication aside as it would very rarely be needed in a well designed application to need on the fly instantiation of multiple interfaces in one go.
But, you can achieve that in a different way though: