SCJP认证试题(九)

xiaoxiao2022-06-12  18

Place the correct Code in the Code Sample to achieve the expected results. 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 [color=red] Answer : B E[/color] 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 [color=red]Answer : C[/color] 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 here25 What is the result? A restore 400 B restore 403 C restore 453 D Compilation fails E An exception is thrown at runtime [color=red]Answer : C[/color] 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 [color=red]Answer : D[/color] 11 public class Yikes{1213 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 [color=red]Answer : A[/color] 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 [color=red] Answer: B[/color] Given : 33 Date d = new Date(0);34 String ds = "December 15, 2004";35 // insert code here36 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()); [color=red]Answer: B [/color] 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. [color=red]Answer: C F[/color] 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 [color=red]Answer: A D E[/color] 相关资源:《Java国际认证(SCJP)典型试题1000例中文版》PDF
转载请注明原文地址: https://www.6miu.com/read-4933127.html

最新回复(0)