ProAnswers.org

What is anonymous inner class ?

It is an inner class whose name is not written in the outer class and for which only one object is created.

An inner class which does not contains any name is called as Anonymous inner class.

import java.awt.*;

import java.awt.event.*;

class FrameDemo extends Frame{

FrameDemo(){

this.setVisible(true);

this.setSize(300,300);

this.setTitle(“Anonymous inner class”);

addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent ae){

System.exit(0);

                 }

        });

}

Public static void main(String[] args){

FrameDemo fd = new FrameDemo();

        }

}