java-programmer, Doubt regarding Interfaces
Thanks everyone for your replies!
I have a basic question - in the above instance Runnable is an
interface and interfaces cannot be instantiated. So something like 'new
Runnable()' seems puzzling to me. Is this syntax for instantiating an
object of the Anonymous class?
Also, is the above snippet similar to the following in the end result:
class ac implements Runnable{
public void run() {
System.out.println("Hello World on " +
Thread.currentThread());
}
};
java-programmer >> Doubt regarding Interfaces
zero wrote:
>
> b.addActionListener(new ActionListener()
> {
public void actionPerformed(ActionEvent event) {
> JOptionFrame.showMessageDialog("button clicked");
}
> });
>
> Note how the whole class definition is inside the parentheses of the
> addActionListener method, and it is ended - like any statement - with a
> semi-colon.
Well, the class ends with the closing }. The enclosing expression
carries on as normal.
Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/