You are really not creating a Runnable. Let me show you show.
So let us look at the following code:
Okay the part that you have to understand is that the Runnable referance variable refers not to an instance of Runnable but to an instance of an anonymous class that implements Runnable. And because this ananoymous class is of type Runnable we still have to follow the rules of polymorhpism (hehe sorry for the spelling). So what does that mean in this situation? It means that we cannot do something like this:
We can only call the methods that that referance type has, which in this case is only run(). Here is one more example and this time I will expand a class and override a method.
So what happend here? The Foo referance refers to an anonymous subclass of Foo that override the fooStuff() method. So what will the output be here? "Override foo stuff"
Anyway read up on inner classes in Java and you will get a better understanding of what is going on.
Jerret Halter<br /> <br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>If you give someone a program, you will frustrate them for a day; if you teach them how to program, you will frustrate them for a lifetime.<hr></blockquote>
posted 13 years ago
Originally posted by sai donthneni: Hi Garrett, if you look at the code more carefully it is not instantiating Runnale interface as there is no semicolon after the Runnable r=new Runnable().
You're right, sorry, the formatting threw mw off.
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Bras cause cancer. And tiny ads:
Create Edit Print & Convert PDF Using Free API with Java