previous | start | next

Self Check

  1. Consider the following runnable.
    public class MyRunnable implements Runnable
    {
       public void run()
       {
          try
          {
             System.out.println(1);
             Thread.sleep(1000);
             System.out.println(2);
          }
          catch (InterruptedException exception)
          {
             System.out.println(3);
          }
          System.out.println(4);
       }
    }
    Suppose a thread with this runnable is started and immediately interrupted.
    Thread t = new Thread(new MyRunnable());
    t.start();
    t.interrupt();
    What output is produced?

previous | start | next