-
What is the output of this program?
class Mythread extends Thread
{
Thread thread;
Mythread()
{
thread = new Thread(this,"New Thread");
thread.start();
}
public void run()
{
try
{
thread.join();
System.out.println(thread.getName());
}
catch(Exception e)
{
System.out.print("Exception");
}
}
}
public class multithreaded_programing
{
public static void main(String args[])
{
new Mythread();
}
}
-
- New Thread
- Thread
- My Thread
- Compilation Error
- Runtime Error
Correct Option: E
join() method of Thread class waits for thread being called to finish or terminate, but here we have no condition which can terminate the thread, hence code ‘thread.join()’ leads to runtime error and nothing will be printed on the screen.