- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are anonymous inner classes in Java?
An inner class declared without a class name is known as an anonymous inner class.
- we declare and instantiate them at the same time.
- In general, they are used whenever you need to override the method of a class or an interface.
Example
abstract class AnonymousInner { public abstract void myMethod(); } public class Outer_class { public static void main(String args[]) { AnonymousInner inner = new AnonymousInner() { public void myMethod() { System.out.println("This is an example of anonymous inner class"); } }; inner.myMethod(); } }
Output
This is an example of anonymous inner class
- Related Articles
- How are anonymous (inner) classes used in Java?
- How many types of anonymous inner classes are defined in Java?
- What are inner classes in Java?
- What are method local inner classes in Java?
- Anonymous classes in C++
- PHP Anonymous classes
- What is the difference between static classes and non-static inner classes in Java?
- Anonymous classes in PHP 7?
- Why do we need inner classes in Java?
- What are Java classes?
- How to implement an interface using an anonymous inner class in Java?
- What are final classes in Java?
- What are abstract classes in Java?
- What are wrapper classes in Java?
- What are I/O classes in Java?

Advertisements