1.

Anonymous Inner Class in Java

Answer»

An anonymous class is an inner class that does not have any name in Java. Only a single object of this class is created. An instance of an object can be created with more features such as OVERLOADING methods of a class by using the anonymous inner class. This can be done without having to subclass a class.

A PROGRAM that demonstrates the anonymous inner class in Java is given as follows:

interface Num {    int num = 50;    void getNum(); } public class Demo {    public static void main(STRING[] args)    {        Num obj = new Num()        {            @Override            public void getNum()            {                System.out.print("The number is: " + num);            }        };        obj.getNum();    } }

In the above example an anonymous inner class is used and the object of that is created as WELL as copied in the class code.



Discussion

No Comment Found