This is a program from Vals exam can someone explain path of execution of this program. Thanks [Edited by Val - Added code tags] [ July 02, 2002: Message edited by: Valentin Crettaz ]
Runnable is an interface and can't be instancitated. however, the in-line implementation of the runnable interface can be done as shown in the original code, as an annonymous inner class and doesn't require the implements clause.
In the your original code.. you are creating the anonymous inner class(Runnable implicitly implementing Runnable interface) in the thread constructor. providing the implementation for run and then scheduling the thread using start().
Thread t = new Thread(new Runnable(){public void run(){for(int j=0;j<=i;j++){System.out.print(" "+j);}}}); This one statement is a way of creating an annonymous object of Runnable interface ??? Is my understanding right? I still wonder how Runnable gets implicitly implemented is that true with any interface. Thnx for ur replies B
Thread t = new Thread(new Runnable(){ public void run(){ for(int j=0;j<=i;j++){ System.out.print(" "+j); } } }); This one statement is a way of creating an annonymous object of Runnable interface ???
That's correct. although the syntaxt may be a little bit strange, you are actually implementing the Runnable interface. You can implement any interface like that as an anonymous inner class, the same you do with event listener interfaces.
Amir
Don't get me started about those stupid light bulbs.