Anonymous Inner Class in Java

There is a concept called anonymous inner class.Basically what it means is creating class without a name and for which only a single object can be created.
It is useful in graphics programming.
Following is the code

interface Age {
    int x = 26;
    void getAge();
}

class MyClass implements Age {

    @Override
    public void getAge() {
        System.out.println("The age is " + x);
    }
}

public class anonymous {
    public static void main(String[] args) {
        MyClass myClass = new MyClass();
        myClass.getAge();
    }
}

//Running This program gives the output
//The age is 26

Here MyClass is written as an implementtaion of Age.With the help of anonymous class concept , we can directly copy teh code for MyClass and put in the main class as below:

interface Age {
    int x = 26;
    void getAge();
}

public class anonymous {
    public static void main(String[] args) {
       Age age = new Age() {
           @Override
           public void getAge() {
                System.out.println("The age is: "+ x);
           }
       };
       age.getAge();
    }
}
//Running This program gives the output
//The age is 26

This is one of the cool tricks which is beneficial and also good to know the concepts.
There are other ways of anonymous inner class,some of them are:

//Implementing a class through anonymous inner class
public class anonymous {
    public static void main(String[] args) {
        Thread thread = new Thread()
        {
            public void run()
            {
                System.out.println("Child Thread");
            }
        };
        thread.start();
        System.out.println("Its Parent class");
    }
}
//output:Its Parent class
//       Child Thread

//Implementing a interface through anonymous inner class
public class anonymous {
    public static void main(String[] args) {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("Child Thread");
            }
        };
        Thread thread = new Thread(runnable);
        thread.start();
        System.out.println("Its Parent class");
    }
}
//output:Its Parent class
//       Child Thread

//Implementing inside method/constructor arguement
public class anonymous {
    public static void main(String[] args) {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("Child Thread");
            }
        });
        thread.start();
        System.out.println("Its Parent class");
    }
}
//output:Its Parent class
//       Child Thread

Differences between normal class and anonymous inner class:
-> A normal class can implement any number of interfaces but an anonymous inner class can implement one only interface at a time.
-> A normal class can extend a class and implements any number of interfaces but anonymous inner class can extend or implement but not both at a time.