What will be the result of attempting to compile and run the following program?
public class Main extends Thread { public Main(String s) { msg = s; } String msg;//from w w w .j av a 2 s . co m public void run() { System.out.println(msg); } public static void main(String[] args) { new Main("Hello"); new Main("World"); } }
Select the one correct answer.
(e)
The program will compile without errors and will simply terminate without any output when run.
Two thread objects will be created, but they will never be started.
The start()
method must be called on the thread objects to make the threads execute the run()
method asynchronously.