+ 1

What is the output of the following program?

public class Test extends Thread implements Runnable { public void run( ) { System.out.printf("GMC"); } public static void main (String [ ] harga) throws Interrupted Exception { Test obj= new Test( ); obj. run( ); obj. start( ); } }

5th Feb 2020, 4:33 PM
Asit Das
Asit Das - avatar
1 Respuesta
0
It should print GMC twice. Also there is no need to extend and implement both. Any one of them, either the Thread class or the Runnable interface will do the job. Also the run() do not create a new thread and is executed within the current thread which is main(). Whereas the start() creates a new thread and a separate stack memory is allocated for its execution. Also you probably have a runtime error because InterruptedException is a single word and there is no space in between.
5th Feb 2020, 4:46 PM
Avinesh
Avinesh - avatar