Wednesday, May 24, 2006

Anonymous Class

Unlike mormal classses Anonymous classes don't have name (therefore anonymous class). Because they don't have name, it's not possible to refer them. Therefore we have to declare them when we create them. Following is the famous example -

JButton normalButton = new JButton();

normalButton.addActionListener( new ActionListener() {

public void actionPerformed ( ActionEvent e )
{
normalText.setText("Hi text");
}

} );


Anoymous classes are created using "new" operator and without "class" keyword.

0 Comments:

Post a Comment

<< Home