Home » JAVA Programming » Multithreading » Question
  1. What is the output of this program?
    class N extends Thread
    {
    Thread thread;
    String Str;
    N(String ThreadName)
    {
    Str = ThreadName;
    thread = new Thread(this,Str);
    thread.start();
    }
    public void run()
    {
    }

    }

    public class multithreading_Example
    {
    public static void main(String args[])
    {
    N object1 = new N("First");
    N object2 = new N("Second");
    try
    {
    object1.thread.wait();
    System.out.print(object1.thread.isAlive());
    }
    catch(Exception e)
    {
    System.out.print("Running Main Thread...");
    }
    }
    }
    1. First
    2. Second
    3. Running Main Thread...
    4. All of above
    5. None of these
Correct Option: C

object1.thread.wait() causes main thread to go out of processing in sleep state hence causes exception and “Main thread interrupted” is printed.



Your comments will be displayed only after manual approval.