|
Question 1. 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 Question 2. Which two statements are true? (Choose two.) A. It is possible for more than two threads to deadlock at once. B. The JVM implementation guarantees that multiple threads cannot enter into a deadlocked state. C. Deadlocked threads release once their sleep() method's sleep duration has expired. D. Deadlocking can occur only when the wait(), notify(), and notifyAll() methods are used incorrectly. E. It is possible for a single-threaded application to deadlock if synchronized blocks are used incorrectly. F. If a piece of code is capable of deadlocking, you cannot eliminate the possibility of deadlocking by inserting invocations of Thread.yield(). Answer: A, F Question 3. Given: 7. void waitForSignal() { 8. Object obj = new Object(); 9. synchronized (Thread.currentThread()) { 10. obj.wait(); 11. obj.notify(); 12. } 13. } Which statement is true? A. This code can throw an InterruptedException. B. This code can throw an IllegalMonitorStateException. C. This code can throw a TimeoutException after ten minutes. D. Reversing the order of obj.wait() and obj.notify() might cause this method to complete normally. E. A call to notify() or notifyAll() from another thread might cause this method to complete normally. F. This code does NOT compile unless "obj.wait()" is replaced with "((Thread) obj).wait()". Answer: B Question 4. Click the Exhibit button. What is the output if the main() method is run? A. 4 B. 5 C. 8 D. 9 E. Compilation fails. F. An exception is thrown at runtime. G. It is impossible to determine for certain. Answer: D Question 5. Given: 11. class PingPong2 { 12. synchronized void hit(long n) { 13. for(int i = 1; i < 3; i++) 14. System.out.print(n + "-" + i + " "); 15. } 16. } 17. public class Tester implements Runnable { 18. static PingPong2 pp2 = new PingPong2(); 19. public static void main(String[] args) { 20. new Thread(new Tester()).start(); 21. new Thread(new Tester()).start(); 22. } 23. public void run() { pp2.hit(Thread.currentThread().getId()); } 24. } Which statement is true? A. The output could be 5-1 6-1 6-2 5-2 B. The output could be 6-1 6-2 5-1 5-2 C. The output could be 6-1 5-2 6-2 5-1 D. The output could be 6-1 6-2 5-1 7-1 Answer: B Question 6. Given: 1. public class Threads4 { 2. public static void main (String[] args) { 3. new Threads4().go(); 4. } 5. public void go() { 6. Runnable r = new Runnable() { 7. public void run() { 8. System.out.print("foo"); 9. } 10. }; 11. Thread t = new Thread(r); 12. t.start(); 13. t.start(); 14. } 15. } What is the result? A. Compilation fails. B. An exception is thrown at runtime. C. The code executes normally and prints "foo". D. The code executes normally, but nothing is printed. Answer: B Question 7. Given: 11. public abstract class Shape { 12. private int x; 13. private int y; 14. public abstract void draw(); 15. public void setAnchor(int x, int y) { 16. this.x = x; 17. this.y = y; 18. } 19. } Which two classes use the Shape class correctly? (Choose two.) A. public class Circle implements Shape { private int radius; } B. public abstract class Circle extends Shape { private int radius; } C. public class Circle extends Shape { private int radius; public void draw(); } D. public abstract class Circle implements Shape { private int radius; public void draw(); } E. public class Circle extends Shape { private int radius; public void draw() {/* code here */} F. public abstract class Circle implements Shape { private int radius; public void draw() { /* code here */ } Answer: B, E Question 8. Given: 11. public class Barn { 12. public static void main(String[] args) { 13. new Barn().go("hi", 1); 14. new Barn().go("hi", "world", 2); 15. } 16. public void go(String... y, int x) { 17. System.out.print(y[y.length - 1] + " "); 18. } 19. } What is the result? A. hi hi B. hi world C. world world D. Compilation fails. E. An exception is thrown at runtime. Answer: D Question 9. Given: 10. class Nav{ 11. public enum Direction { NORTH, SOUTH, EAST, WEST } 12. } 13. public class Sprite{ 14. // insert code here 15. } Which code, inserted at line 14, allows the Sprite class to compile? A. Direction d = NORTH; B. Nav.Direction d = NORTH; C. Direction d = Direction.NORTH; D. Nav.Direction d = Nav.Direction.NORTH; Answer: D Question 10. Click the Exhibit button. Which statement is true about the classes and interfaces in the exhibit? A. Compilation will succeed for all classes and interfaces. B. Compilation of class C will fail because of an error in line 2. C. Compilation of class C will fail because of an error in line 6. D. Compilation of class AImpl will fail because of an error in line 2. Answer: C
Copyright © 2004 CertsBraindumps.com Inc. All rights reserved.