What will be the result of attempting to compile and run the following program?
public class Worker extends Thread { public void run() { System.out.print("|work|"); }/*w w w.j a v a 2 s .c om*/ public static void main(String[] args) { Worker worker = new Worker(); worker.start(); worker.run(); worker.start(); } }
Select the one correct answer.
(d)
The call to the run()
method just executes the method in the main thread.
Once a thread has terminated, it cannot be started by calling the start()
method as shown above.
A new thread must be created and started.