浏览 1810 次
锁定老帖子 主题:SCJP认证试题(九)
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-11-23
Expected results: Output :1 2 4 8 16 32 Code Sample int[] y = {1,2,4,8,16,32}; System.out.print("Output:"); [place here] System.out.print(x); System.out.print(""); } Code [for(int x:y){] [for(int x=y[]){] [foreach(y as x){] [foreach(int x:y){] [for(int x=1;x=y[];x++)] Answer: int[] y = {1,2,4,8,16,32}; System.out.print("Output:"); for(int x:y){ System.out.print(x); System.out.print(""); } 8 public class Test{ 9 public static void main(String[] a){ 10 assert a.length == 1; 11 } 12 } Which two will produce an AssertionError?(choose two) A java test B java -ea test C java test file1 D java -ea test file1 E java -ea test file1 file2 F java -ea:test test file1 Answer : B E 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 statement is true if a ResouceException 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 thrown an exception to its caller Answer : C Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java serialization and given: 13 import java.io.*; 14 class Food implements Serializable{int good = 3;} 15 class Fruit extends Food{int juice = 5;} 16 public class Banana extends Fruit{ 17 int yellow = 4; 18 public static void main(String[] args){ 19 Banana b = new Banana(); 20 b.serializeBanana(b); 21 b2 = b.deserializeBanana(); 22 System.out.println("restore" + b2.yellow + b2.juice + b2.good); 23 } 24 //more Banana methods go here 25 What is the result? A restore 400 B restore 403 C restore 453 D Compilation fails E An exception is thrown at runtime Answer : C Given : 12 System.out.format("Pi is approximately %d", Math.PI); What is the result? A Compilation fails B Pi is approximately 3. C Pi is approximately 3.141593 D An exception is thrown at runtime Answer : D 11 public class Yikes{ 12 13 public static void go(Long n){System.out.println("Long ");} 14 public static void go(Short n){System.out.println("Short ");} 15 public static void go(int n){System.out.println("int ");} 16 public static void main(String[] args){ 17 short y = 6; 18 long z = 7; 19 go(y); 20 go(z); 21 } 22 } What is the result? A int Long B Short Long C Compilation fails D An exception is thrown at runtime Answer : A Given this method in a class: 21 public String toString(){ 22 StringBuffer buffer = new StringBuffer(); 23 buffer.append('<'); 24 buffer.append(this.name); 25 buffer.append('>'); 26 return buffer.toString(); 27 } Which statement is true? A This code is NOT thread-safe B The programmer can replace StringBuffer with StringBuilder with no other changes C This code will perform poorly.For better performance,the code should be rewritten:return "<" + this.name + ">"; D This code will perform well and converting the code to use StringBuffer will not enchange the performance Answer: B Given : 33 Date d = new Date(0); 34 String ds = "December 15, 2004"; 35 // insert code here 36 try{ 37 d = df.parse(ds); 38 } 39 catch(ParseException e){ 40 System.out.println("Unable to parse " + ds); 41 } 42 // insert code here too What creates the approprivate DateFormat object and adds a day to the Date object? A 35.DateFormat df = DateFormat.getDateFormat(); 42.d.setTime((60*60*24) + d.getTime()); B 35.DateFormat df = DateFormat.getDateInstance(); 42.d.setTime((1000*60*60*24) + d.getTime()); C 35.DateFormat df = DateFormat.getDateFormat(); 42.d.setLocalTime((1000*60*60*24) + d.getLocalTime()); D 35.DateFormat df = DateFormat.getDateInstance(); 42.d.setLocalTime((60*60*24) + d.getLocalTime()); Answer: B Given : 12 NumberFormat nf = NumberFormat.getInstance(); 13 nf.setMaxinumFractionDigits(4); 14 nf.setMininumFractionDigits(2); 15 String a = nf.format(3.1415926); 16 String b = nf.format(2); Which two statements are true about the result if the locale is Locale.US?(Choose two) A The value of b is 2 B The value of a is 3.14 C The value of b is 2.00 D The value of a is 3.141 E The value of a is 3.1415 F The value of a is 3.1416 G The value of b is 2.0000. Answer: C F 1 import java.util.*; 2 public class Old{ 3 public static Object get0(List list){ 4 return list.get(0); 5 } 6 } Which three will compile successfully?(Choose three) A Object o = Old.get0(new LinkedList()); B Object o = Old.get0(new LinkedList<?>()); C String s = Old.get0(new LinkedList<String>()); D Object o = Old.get0(new LinkedList<Object>()); E String s = (String)Old.get0(new LinkedList<String>()); F Answer: A D E 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |