Java OCA OCP Practice Question 3216

Question

Consider the following program:

class ExtendThread extends Thread {
         public void run() { System.out.print(Thread.currentThread().getName()); }
}

public class Main{
         public static void main(String []args) throws InterruptedException {
                 Thread thread1 = new Thread(new ExtendThread(), "thread1 ");
                 Thread thread2 = new Thread(thread1, "thread2 ");
                 thread1.start();/*from  w w  w.ja v  a 2  s  .  c om*/
                 thread2.start();
                 thread1.start();                      // START
         }
}

Which one of the following correctly describes the behavior of this program?

  • A. The program prints the following: thread1 thread2 thread1.
  • B. The program prints the following: thread1 thread1 thread1.
  • C. The program prints the following: thread1 thread2.
  • D. The program results in a compiler error for the statement marked with the comment START.
  • E. The program throws an IllegalMonitorStateException when executing the statement marked with the comment START.


E.

Note

It is illegal to call the start() method more than once on a thread; in that case, the thread will throw an IllegalMonitorStateException.




PreviousNext

Related