Java OCA OCP Practice Question 2873

Question

Given:

3. public class Main extends Thread {  
4.   public static void main(String[] args) {  
5.     Thread t1 = new Thread(new Main());  
6.     t1.start();  //from w  ww.j  av a2s  .  c  o m
7.     t1.join();   
8.     for(int i = 0; i < 1000; i++)  // Loop #1  
9.       System.out.print(Thread.currentThread().getName() + " ");  
10.   }  
11.   public void run() {  
12.     for(int i = 0; i < 1000; i++)  // Loop #2  
13.       System.out.print(Thread.currentThread().getName() + " ");  
14. } } 

Which are true? (Choose all that apply.)

  • A. Compilation fails.
  • B. An exception is thrown at runtime.
  • C. Loop #1 will run most of its iterations before Loop #2.
  • D. Loop #2 will run most of its iterations before Loop #1.
  • E. There is no way to predict which loop will mostly run first.


A is correct.

Note

The join() method throws an exception, so it must be handled or declared; if it was, then D would be correct.




PreviousNext

Related