Given:
class Main extends Thread { Main(String n) {// w w w . jav a 2s.com super(n); } public void run() { for (int i = 0; i < 100; i++) { if ("t1".equals(Thread.currentThread().getName()) && i == 5) { new Main("t3").start(); throw new Error(); } if ("t2".equals(Thread.currentThread().getName()) && i == 5) { new Main("t4").start(); throw new Error(); } System.out.print(Thread.currentThread().getName() + "-"); } } public static void main(String[] args) { Thread t1 = new Main("t1"); Thread t2 = new Main("t2"); t1.setPriority(1); t2.setPriority(9); t2.start(); t1.start(); } }
Which are true? (Choose all that apply.)
A. Compilation fails. B. After throwing error(s), t3 will most likely complete before t4. C. After throwing error(s), t4 will most likely complete before t3. D. The code will throw one error and then no more output will be produced. E. The code will throw two errors and then no more output will be produced. F. After throwing error(s) it's difficult to determine whether t3 or t4 will complete first.
C is correct.
Threads can be constructed with a name.
The errors will stop t1 and t2, but t3 and t4 will continue.
The thread t4 will complete before t3 because it more or less "inherits" its priority from the thread that created it, t2.