Anonymous Inner Class in Java

A class is a non-primitive or user-defined data type in Java, while an object is an instance of a class. To define a class within another class. Such a class is called a Nested Class. An anonymous it 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 overriding methods of a class or interface, without having to actually subclass a class.

Source Code

//Anonymous Inner Class
abstract class testDemo {
    abstract void display();
class outerDemo {
    public void outerDisplay() {
        testDemo o =new testDemo() {
            public void display() {
                System.out.println("Test Display");
public class anonymousInner {
    public static void main(String[] args) {
        outerDemo o =new outerDemo();


Test Display
To download raw file Click Here

Basic Programs