• Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt on interface instantiation in ActionListener class  RSS feed

 
satya sahu
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jButton2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){

}
});
ActionListener is an interface. Interfaces can't be instantiated. Then how in the above anonymous implementation new of the interface is done?
 
Stevi Deter
Ranch Hand
Posts: 265
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satya,

The code you posted is an example of declaring an anonymous inner class. It's a common approach to coding event handlers.

A good introduction can be found here in the Java Tutorials.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!