Page: 1
9. Multi-Threading
Q: 01 Click the Exhibit button. What is the result?
A. The code will deadlock. B. The code may run with no output. C. An exception is thrown at runtime. D. The code may run with output "0 6". E. The code may run with output "2 0 6 4". F. The code may run with output "0 2 4 6". Answer: F Q: 02 Given: 1. public class Threads2 implements Runnable { 2. 3. public void run() { 4. System.out.println("run."); 5. throw new RuntimeException("Problem"); 6. } 7. public static void main(String[] args) { 8. Thread t = new Thread(new Threads2()); 9. t.start(); 10. System.out.println("End of method."); 11. } 12. } Which two can be results? (Choose two.) A. java.lang.RuntimeException: Problem B. run. java.lang.RuntimeException: Problem C. End of method. java.lang.RuntimeException: Problem D. End of method. run. java.lang.RuntimeException: Problem E. run. java.lang.RuntimeException: Problem End of method. Answer: D, E Q: 03 Given: 1. public class TestSeven extends Thread { 2. private static int x; 3. public synchronized void doThings() { 4. int current = x; 5. current++; 6. x = current; 7. } 8. public void run() { 9. doThings(); 10. } 11.}
Page: 1
1
2
3
4
5
6
7
8
9
10
|