+ 5
What is use of Anonymous classes? Any real world reference will be helpful.
2 Answers
+ 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
+ 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.