【WEEK】SCJP考试真题6-10题
weeksky吧
全部回复
仅看楼主
level 6
weeksky 楼主
Q6. Which fragment is an example of inappropriate use of assertions? A. assert (!(map.contains(x))); map.add(x); B. if (x > 0) { } else { assert (x==0); } C. public void aMethod(int x) { assert (x > 0); } D. assert (invariantCondition()); return retval; E. switch (x) { case 1: break; case 2: creak; default: assert (x == 0); Answer: C. Q7. Given: 1. public class X { 2. public static void main(String [] args) { 3. try { 4. badMethod(); 5. System.out.print(“A”); 6. } 7. catch (RuntimeException ex) { 8. System.out.print(“B”); 9. } 10. catch (Exception ex1) { 11. System.out.print(“C”); 12. } 13. finally { 14. System.out.print(“D”); 15. } 16. System.out.print(“E”); 17. } 18. public static void badMethod() { 19. throw new RuntimeException(); 20. } 21. } What is the result? A. BD B. BCD C. BDE D. BCDE E. ABCDE F. Compilation fails. Answer: C. Q8. Given: 1. public class X { 2. public static void main(String [] args) { 3. try { 4. badMethod(); 5. System.out.print(“A”); 6. } 7. catch (Exception ex) { 8. System.out.print(“B”); 9. } 10. finally { 11. System.out.print(“C”); 12. } 13. System.out.print(“D”); 14. } 15. public static void badMethod() { 16. throw new RuntimeException(); 17. } 18. } What is the result? A. AB B. BC C. ABC D. BCD E. Compilation fails. Answer: D. Q9. Which statement is true? A. catch(X x) can catch subclasses of X. B. The Error class us a RuntimeException. C. Any statement that can throw an Error must be enclosed in a try block. D. Any statement that can throw an Exception must be enclosed in a try block. E. Any statement that can throw a RuntimeException must be enclosed in a try block. Answer: B. Q10. Given: 11. for( int i min; i
2007年05月14日 01点05分 1
1