当前位置: 代码迷 >> Java相关 >> SCJP考试题310-025(第二套)51-91/147
  详细解决方案

SCJP考试题310-025(第二套)51-91/147

热度:455   发布时间:2005-01-09 19:28:00.0
SCJP考试题310-025(第二套)51-91/147
310-025 Leading the way in IT testing and certification tools, www.testking.com Question No 51 Exhibit: 1. import java.io.IOException; 2. public class ExceptionTest( 3. public static void main (String[]args) 4. try ( 5. methodA(); 6. ) catch (IOException e) ( 7. system.out.printIn(“Caught IOException”); 8. ) catch (Exception e) ( 9. system.out.printIn(“Caught Exception”); 10. ) 11. ) 12. public void methodA () { 13. throw new IOException (); 14. ) 15. ) What is the result? A. The code will not compile. B. The output is caught exception. C. The output is caught IOException. D. The program executes normally without printing a message. Answer: A Question No 52 Exhibit: 1. public class test { 2. public static string output = “” 3. 4. public static void foo(int i) { 5. try { 6. if(i= =1) { 7. throw new Exception (); 8. } 9. output += “1”; 10. ) 11. catch(Exception e) { 12. output += “2”; 13. return; 14. ) 15. finally ( 16. output += “3”; 17. ) 18. output += “4”; 19. ) 20. 21. public static void main (string args[]) ( 22. foo(0); 23. foo(1); 24. 25. ) 26. ) What is the value of the variable output at line 24? Answer: 13423 Question No 53 Given: 1. public class Foo implements Runnable ( 2. public void run (Thread t) { 3. system.out.printIn(“Running.”); 4. } 5. public static void main (String[] args) { 6. new thread (new Foo()).start(); 7. ) 8. ) What is the result? A. An exception is thrown. B. The program exists without printing anything. C. An error at line 1 causes compilation to fail. D. An error at line 2 causes the compilation to fail. E. “Running” is printed and the program exits. Answer: D Question No 54 Which statement is true? A. If only one thread is blocked in the wait method of an object, and another thread executes the modify on that same object, then the first thread immediately resumes execution. B. If a thread is blocked in the wait method of an object, and another thread executes the notify method on the same object, it is still possible that the first thread might never resume execution. C. If a thread is blocked in the wait method of an object, and another thread executes the notify method on the same object, then the first thread definitely resumes execution as a direct and sole consequence of the notify call. D. If two threads are blocked in the wait method of one object, and another thread executes the notify method on the same object, then the first thread that executed the wait call first definitely resumes execution as a direct and sole consequence of the notify call. Answer: B Question No 55 Which two CANNOT directly cause a thread to stop executing? (Choose Two) A. Calling the yield method. B. Calling the wait method on an object. C. Calling the notify method on an object. D. Calling the notifyAll method on an object. E. Calling the start method on another Thread object. Answer: C, D Question No 56 Which two can be used to create a new Thread? (Choose Two) A. Extend java.lang.Thread and override the run method. B. Extend java.lang.Runnable and override the start method. C. Implement java.lang.thread and implement the run method. D. Implement java.lang.Runnable and implement the run method. E. Implement java.lang.Thread and implement the start method. Answer: A, D Question No 54 Which statement is true? A. If only one thread is blocked in the wait method of an object, and another thread executes the modify on that same object, then the first thread immediately resumes execution. B. If a thread is blocked in the wait method of an object, and another thread executes the notify method on the same object, it is still possible that the first thread might never resume execution. C. If a thread is blocked in the wait method of an object, and another thread executes the notify method on the same object, then the first thread definitely resumes execution as a direct and sole consequence of the notify call. D. If two threads are blocked in the wait method of one object, and another thread executes the notify method on the same object, then the first thread that executed the wait call first definitely resumes execution as a direct and sole consequence of the notify call. Answer: B Question No 55 Which two CANNOT directly cause a thread to stop executing? (Choose Two) A. Calling the yield method. B. Calling the wait method on an object. C. Calling the notify method on an object. D. Calling the notifyAll method on an object. E. Calling the start method on another Thread object. Answer: C, D Question No 56 Which two can be used to create a new Thread? (Choose Two) A. Extend java.lang.Thread and override the run method. B. Extend java.lang.Runnable and override the start method. C. Implement java.lang.thread and implement the run method. D. Implement java.lang.Runnable and implement the run method. E. Implement java.lang.Thread and implement the start method. Answer: A, D Question No 57 Given: 1. public class SyncTest ( 2. private int x; 3. private int y; 4. private synchronized void setX (int i) (x=1;) 5. private synchronized void setY (int i) (y=1;) 6. public void setXY(int 1)(set X(i); setY(i);) 7. public synchronized Boolean check() (return x !=y;) 8. ) Under which conditions will check () return true when called from a different class? A. Check() can never return true. B. Check() can return true when setXY is called by multiple threads. C. Check() can return true when multiple threads call setX and setY separately. D. Check() can only return true if SyncTest is changed to allow x and y to be set separately. Answer: B Question No 58 Exhibit: 1. class A implements runable ( 2. int i; 3. public void run () ( 4. try ( 5. thread.sleep(5000); 6. i= 10; 7. ) catch(InterruptedException e) {} 8. ) 9. ) 10. 11. public class Test { 12. public static void main (string args[]) ( 13. try ( 14. A a = new A (); 15. Thread t = new Thread (a); 16. t.start(); 17. 18. int j= a.i; 19. 20. ) catch (Exception e) {} 21. ) 22. ) Which statement al line 17 will ensure that j=10 at line 19? A. a.wait(); B. t.wait(); C. t.join(); D. t.yield(); E. t.notify(); F. a.notify(); G. t.interrupt(); Answer: C Question No 59 Exhibit: 1. public class X implements Runnable ( 2. private int x; 3. private int y; 4. 5. public static void main(String [] args) ( 6. X that = new X(); 7. (new Thread(that)) . start( ); 8. (new Thread(that)) . start( ); 9. ) 10. 11. public synchronized void run( ) ( 12. for (;;) ( 13. x++; 14. y++; 15. System.out.printIn(“x = “ + x + “, y = “ + y); 16. ) 17. ) 18. ) What is the result? A. An error at line 11 causes compilation to fail. B. Errors at lines 7 and 8 cause compilation to fail. C. The program prints pairs of values for x and y that might not always be the same on the same line (for example, “x=2, y=1”) D. The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by “x=1, y=1”) E. The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by “x=2s, y=2”) Answer: E QUESTION N 60 Which two CANNOT directly cause a thread to stop executing? (Choose Two) A. Existing from a synchronized block. B. Calling the wait method on an object. C. Calling notify method on an object. D. Calling read method on an InputStream object. E. Calling the SetPriority method on a Thread object. Answer: A, C QUESTION N 61 Exhibit 1. public class SyncTest{ 2. public static void main(String[] args) { 3. final StringBuffer s1= new StringBuffer(); 4. final StringBuffer s2= new StringBuffer(); 5. new Thread () { 6. public void run() { 7. synchronized(s1) { 8. s2.append(“A”); 9. synchronized(s2) { 10. s2.append(“B”); 11. System.out.print(s1); 12. System.out.print(s2); 13. } 14. } 15. } 16. }.start(); 17. new Thread() { 18. public void run() { 19. synchronized(s2) { 20. s2.append(“C”); 21. synchronized(s1) { 22. s1.append(“D”); 23. System.out.print(s2); 24. System.out.print(s1); 25. } 26. } 27. } 28. }.start(); 29. } 30. } Which two statements are true? (Choose Two) A. The program prints “ABBCAD” B. The program prints “CDDACB” C. The program prints “ADCBADBC” D. The output is a non-deterministic point because of a possible deadlock condition. E. The output is dependent on the threading model of the system the program is running on. Answer: D, B QUESTION N 62 Which method in the Thread class is used to create and launch a new thread of execution? A. Run(); B. Start(); B. Execute(); C. Run(Runnable r); D. Start(Runnable r); E. Execute(Thread t); Answer: B - QUESTION N 63 Given: 5. String foo = “base”; 6. foo.substring(0,3); 7. foo.concat(“ket”)
程序代码:
<SCRIPT type=text/javascript>