Why Java interface can be instantiated in these codes? [duplicate]
Possible Duplicate: Creating an “object” of an interface I am new to Java. Based on my understanding: We cannot instantiate an Interface . We can only instantiate a class which implements an interface . The new keyword is used to create an object from a class. However, when I read the source codes of some Java programs, I found that sometimes an Interface is instantiated. For example: Example 1: JButtonObject.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //codes } }); Example 2: SwingUtilities.invokeLater(new Runnable() { public void run() { //codes } })