Styrow.dev
Question 127 of 247
Java Topic: General medium

Can an anonymous class define method of its own?

Question

Can an anonymous class define method of its own?

Answer

Yes. But there will be no way by which the methods defined in the anonymous class which are not present in its superclass be invoked. As only those methods which are defined in the suprclass which the anonymous class extends be invoked defining the methods in the anonymous class will be of no use.