Java OCA OCP Practice Question 2841

Question

Given:

3. public class Main {  
4.   public static void main(String[] args) {  
5.     MyClass h = new MyClass();  
6.     Thread t1 = new Thread(h, "Java");  
7.     Thread t2 = new Thread(h, "Jack");  
8.     new Main().go(t2);  
9.     t1.start();  //from ww w  . j a  v a  2s.  c o  m
10.     t2.start();  
11.   }  
12.   void go(Thread t) { t.start(); }  
13. }  
14. class MyClass implements Runnable {  
15.   public void run() {  
16.     System.out.print(Thread.currentThread().getName() + " ");  
17. } } 

What is the result? (Choose all that apply.).

  • A. Compilation fails.
  • B. No output is produced.
  • C. The output could be: "Java Jack"
  • D. The output could be: "Jack Java Jack"
  • E. The output could be: "Jack", followed by an exception.
  • F. The output could be: "Jack Java", followed by an exception.


E and F are correct.

Note

Line 10 will throw an exception because you can't start the same thread (in this case, t2) more than once.




PreviousNext

Related