1In Java, it is possible to define a class within another class, such
2classes are known as nested classes. They enable you to logically group
3classes that are only used in one place, thus this increases the use of
4encapsulation, and creates more readable and maintainable code.
1// Anonymous inner class in java
2abstract class Anonymous
3{
4 public abstract void display();
5}
6public class AnonymousInnerExample
7{
8 public static void main(String[] args)
9 {
10 Anonymous obj = new Anonymous() {
11 public void display() {
12 System.out.println("anonymous inner class example");
13 }
14 };
15 obj.display();
16 }
17}