КАТЕГОРИИ:
АстрономияБиологияГеографияДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРиторикаСоциологияСпортСтроительствоТехнологияФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника
|
Class TestException1. public class TestException extends Exception { 2. } Class A: 1. public class A { 3. public String sayHello(String name) throws TestException { 5. if(name == null) { 6. throw new TestException(); 7. } 9. return "Hello "+ name; 10. } 12. } A programmer wants to use this code in an application: 45. A a=new A(); 46. System.out.println(a.sayHello("John")); Which two are true? (Choose two.) A. Class A will not compile. B. Line 46 can throw the unchecked exception TestException. C. Line 45 can throw the unchecked exception TestException. D. Line 46 will compile if the enclosing method throws a TestException. E. Line 46 will compile if enclosed in a try block, where TestException is caught.
77. Given: 33. try { 34. // some code here 35. } catch (NullPointerException e1) { 36. System.out.print("a"); 37. } catch (RuntimeException e2) { 38. System.out.print("b"); 39. } finally { 40. System.out.print("c"); 41. } What is the result if a NullPointerException occurs on line 34? A. c B. a C. ab D. ac E. bc F. abc
78. Given: 11. classA { 12. public void process() { System.out.print("A,"); } } 13. class B extends A { 14. public void process() throws IOException { 15. super.process(); 16. System.out.print("B,"); 17. throw new IOException(); 18. } } 19. public static void main(String[] args) { 20. try { new B().process(); } 21. catch (IOException e) { System.out.println("Exception"); } } What is the result? A. Exception B. A,B,Exception C. Compilation fails because of an error in line 20. D. Compilation fails because of an error in line 14. E. A NullPointerException is thrown at runtime.
79. Which two code fragments will execute the method doStuff() in a separate thread? (Choose two.) A. new Thread() { public void run() { doStuff(); } } B. new Thread() { public void start() { doStuff(); } } C. new Thread() { public void start() { doStuff(); } } .run(); D. new Thread() { public void run() { doStuff(); } } .start(); E. new Thread(new Runnable() { public void run() { doStuff(); } } ).run(); F. new Thread(new Runnable() { public void run() { doStuff(); } }).start(); 80. Given: 11. static classA { 12. void process() throws Exception { throw new Exception(); } 13. } 14. static class B extends A { 15. void process() { System.out.println("B "); } 16. } 17. public static void main(String[] args) { 18. A a=new B(); 19. a.process(); 20.} What is the result? A. B B. The code runs with no output. C. An exception is thrown at runtime. D. Compilation fails because of an error in line 15. E. Compilation fails because of an error in line 18. F. Compilation fails because of an error in line 19. 81. Given: 11. static class A { 12. void process() throws Exception { throw new Exception(); } 13. } 14. static class B extends A { 15. void process() { System.out.println("B"); } 16. } 17. public static void main(String[] args) { 18. new B().process(); 19. } What is the result? A. B B. The code runs with no output. C. Compilation fails because of an error in line 12. D. Compilation fails because of an error in line 15. E. Compilation fails because of an error in line 18.
82. Given: 84. try { 85. ResourceConnection con = resourceFactory.getConnection(); 86. Results r = con.query("GET INFO FROM CUSTOMER"); 87. info = r.getData(); 88. con.close(); 89. } catch (ResourceException re) { 90. errorLog.write(re.getMessage()); 91. } 92. return info; Which is true if a ResourceException is thrown on line 86? A. Line 92 will not execute. B. The connection will not be retrieved in line 85. C. The resource connection will not be closed on line 88. D. The enclosing method will throw an exception to its caller.
|