+ 5

What is use of Anonymous classes? Any real world reference will be helpful.

25th May 2020, 5:19 PM
Sudarshan Phalke
Sudarshan Phalke - avatar
2 Réponses
+ 4
Anonymous classes are useful when you need to override certain behaviors of a class instance without creating a new or a subclass. They let you make changes on the go. The below code is a basic demonstration on how anonymous inner classes could be used to override behaviour. https://code.sololearn.com/chJsX8p78r77/?ref=app
25th May 2020, 5:41 PM
Avinesh
Avinesh - avatar
+ 1
Anonymous class is a class which has no name given to it. Java supports this feature. These classes cannot have a constructor but can have a destructor. These classes can neither be passed as arguments to functions nor can be used as return values from functions.
25th May 2020, 5:25 PM
Isaac Duah [Active!]
Isaac Duah [Active!] - avatar