Anonymous Class Declarations : Anonymous Class « Object Oriented « SCJP






import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

public class MainClass {
  public static void main(String[] argv) {
    JButton theButton = new JButton();

    new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        System.out.println("The action has occurred");
      }
    };

  }
}








6.9.Anonymous Class
6.9.1.Create an anonymous class
6.9.2.Anonymous Class Declarations
6.9.3.You might assign the reference to the constructed object into a variable
6.9.4.Passing Anonymous Class to a method
6.9.5.Passing Arguments into the Construction of an Anonymous Inner Class
6.9.6.Anonymous Classes: class or interface
6.9.7.An instance of an anonymous (unnamed) subclass of MyClass.