浏览 1795 次
锁定老帖子 主题:SCJP认证试题(六)
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-11-18
/** * * @author yaoyuan */ public class A{ public void method1(){ B b = new B(); b.method2(); 5 //more code here } } public class B{ public void method2(){ C c = new C(); c.method3(); 5 //more code here } } public class C{ public void method3(){ //more code here } } try{ A a = new A(); 27 a.methor1(); } catch(Exception e){ 29 System.out.print("an error occurred"); } /** *Which two statements are true if a NullPointerException is thrown on line 13 of class C?(choose two) * * *A The application will crash *B The code on line 29 will be executed *C The code on line 5 of class A will execute *D The code on line 5 of class B will execute *E The exception will be propagated back to line 27 */ // Answer : B E /** * * @author yaoyuan */ 25 int x = 12; 26 while(x < 10){ 27 x--; 28 } 29 System.out.print(x); /** *What is the result? * * *A 0 *B 10 *C 12 *D Line 29 will never be reached */ // Answer : C /** * * @author yaoyuan */ 1 public class CertKiller2{ 2 Integer I; 3 int x; 4 5 public CertKiller2(int y){ 6 x = I + y; 7 System.out.println(x); 8 } 9 10 public static void main(String[] args){ 11 new CertKiller2(new Integer(4)); 12 } 13 } /** *What is the result? * * *A The value "4" is printed at the command line *B Compilation fails because of an error in line 6 *C Compilation fails because of an error in line 11 *D A NullPointerException occursatruntime *E A NumberForm at Exception occursatruntime *F An IllegalStateException occursatruntime */ // Answer : D /** * * @author yaoyuan */ 1 public static Iterator reverse(List list){ 2 Collections.reverse(list); 3 return list.iterator(); 4 } 5 public static void main(String[] args){ 6 List list = new ArrayList(); 7 list.add("1");list.add("2");list.add("3"); 8 for(Object obj; reverse(list)) 9 System.out.print(obj + ", "); 10 } /** *What is the result? * * *A 3,2,1 *B 1,2,3 *C Compilation fails *D The code runs with no output *E An exception is thrown at runtime */ // Answer : C /** * * @author yaoyuan */ 11 public void testIfA(){ 12 if(testIfB("true")){ 13 System.out.println("True"); 14 }else{ 15 System.out.println("Not true"); 16 } 17 } 18 public Boolean testIfB(String str){ 19 return Boolean.valueof(str); 20 /** *What is the result when method testIfA is invoked? * * *A True *B Not true *C An exception is thrown at runtime *D Compilation fails because of an error at line 12 *E Compilation fails because of an error at line 19 */ // Answer : A /** * * @author yaoyuan */ 23 int z = 5; 24 25 public void CertKiller1(int x){ 26 assert(x > 0); 27 switch(x){ 28 case 2 x=3; 29 default; assert false; }} 30 31 private void CertKiller2(int y){assert(y < 0);} 32 33 private void CertKiller4(){assert(CertKiller4());} 34 35 private Boolean CertKiller4(){z = 6; return false;} /** *Which statement is true? * * *A All of the assert statements are used appropriately *B Only the assert statements line 31 is used appropriately *C The assert statements on lines 29 and 31 are used appropriately *D The assert statements on lines 26 and 29 are used appropriately *E The assert statements on lines 29 and 33 are used appropriately *F The assert statements on lines 29 ,31 and 33 are used appropriately *G The assert statements on lines 26, 29 and 31 are used appropriately */ // Answer : C /** * * @author yaoyuan */ 11 public static void main(String[] args){ 12 String str = "null"; 13 if(str == null){ 14 System.out.println("null"); 15 }else(str.length() == 0){ 16 System.out.println("zero"); 17 }else{ 18 System.out.println("some"); 19 } 20 } /** *What is the result? * * *A null *B zero *C some *D Compilation fails *E An exception is thrown at runtime */ // Answer : D /** * * @author yaoyuan */ 11 public static void main(String[] args){ 12 try{ 13 args = null; 14 aegs[0] = "test"; 15 System.out.println(args[0]); 16 }catch(Exception ex){ 17 System.out.println("Exception"); 18 }catch(NullPointerException npe){ 19 System.out.println("NullPointerException"); 20 } 21 } /** *What is the result? * * *A test *B Exception *C Compilation fails *D NullPointerException */ // Answer : C /** * * @author yaoyuan */ 1 import java.util.*; 2 3 public class LetterASort{ 4 public static void main(String[] args){ 5 ArrayList<String> strings = new ArrayList<String>(); 6 strings.add("aAaA"); 7 strings.add("AaAa"); 8 strings.add("aAa"); 9 strings.add("AAaa"); 10 Collections.sort(strings); 11 for(String s : strings) {System.out.print(s + " ");} 12 } 13 } /** *What is the result? * * *A Compilation fails *B aA aA aA a A A aa A aA *C AA aa AaA aA aAa aA aA *D A aA AA aa aA aA aAa *E aAa AaA aA aA AA aa *F An exception is thrown at runtime */ // Answer : C /** * * @author yaoyuan */ 1 import java.util.*; 2 public class WrappedString{ 3 private String s; 4 public WappedString(String s){this.s = s;} 5 public static void main(String[] args){ 6 HashSet<Object> hs = new HashSet<Object>(); 7 WappedString ws1 = new WappedString("aardvark"); 8 WappedString ws2 = new WappedString("aardvark"); 9 String s1 = new String("aardvark"); 10 String s2 = new String("aardvark"); 11 hs.add(ws1);hs.add(ws2);hs.add(s1);hs.add(s2); 12 System.out.println(hs.size());}} /** *What is the result? * * *A 0 *B 1 *C 2 *D 3 *E 4 *F Compilation fails *G An exception is thrown at runtime */ // Answer : D 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |