USE of ANONYMOUS CLASS IN JAVA
Anonymous class is an inner class without a name and for which only a single object is created. An anonymous inner class can be useful when making an instance of an object with certain “extras” such as overloading methods of a class or interface, without having to actually subclass a class.
Watch this video on our YouTube channel for better understanding, else, keep reading.
There are two ways to create Anonymous inner :
- Class (may be abstract or concrete)
- Interface
Anonymous Inner Class example:
This program shows how to override the method of a class using anonymous inner class.
Anonymous Inner Class as Argument:
This program shows how to pass an anonymous inner class as a method argument.
Important facts about concerning anonymous classes:
- An anonymous class cannot have a constructor. so, there is no need to pass parameters to an anonymous class while instantiating it.
- Can be instantiated only once.
- Cannot be static.
- Has no name.
Hope this article helps you understand the concept of anonymous inner classes in Java programming language better. For more such content, subscribe to our blog.
Like & follow us on Facebook – https://www.facebook.com/pristinetechschool/
Let us know if you have any suggestions/feedback for us in the comment section below.
Happy Coding.
I and my pals have been reviewing the good helpful hints from your web site then then developed an awful suspicion I had not expressed respect to the website owner for those secrets. These young men appeared to be absolutely thrilled to read through them and have now clearly been having fun with those things. I appreciate you for getting well accommodating and then for having certain smart information millions of individuals are really wanting to learn about. My very own sincere apologies for not expressing gratitude to earlier.