Question discussion

What will happen when you attempt to compile and run the following code?1. public class Test extends Thread{2. public static void main(Stri…

299879Medium 1 reply 1,007 views
0
What will happen when you attempt to compile and run the following code?1. public class Test extends Thread{2. public static void main(String argv[]){3. Test t = new Test();4. t.run();5. t.start();6. }7. public void run(){8. System.out.println("run-test");9. }10. }
  • Arun-test run-test
  • Brun-test
  • CCompilation fails due to an error on line 4
  • DCompilation fails due to an error on line 7
  • ENone of these
Correct answer: A

Discussion 1

0
CCommunity
run-test run-test

t.run() Legal, but does not start a new thread , it is like a method call of a class Test BUT t.start() creates a thread and call run() method.