yuanyao 发表于 2013-1-27 04:40:57

SCJP认证试题(九)

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:");System.out.print(x);System.out.print("");}


Code
){]      ;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("");}


8public class Test{9public static void main(String[] a){10assert a.length == 1;11}12}

Which two will produce an AssertionError?(choose two)


Ajava test
Bjava -ea test
Cjava test file1
Djava -ea test file1
Ejava -ea test file1 file2
Fjava -ea:test test file1

Answer : B E


84try{85ResourceConnection con = resourceFactory.getConnection();86Results r = con.query("GET INFO FROM CUSTOMER");87info = r.getData();88con.close();89}catch(ResourceException re){90errorLog.write(re.getMessage());91}92return info;

Which statement is true if a ResouceException is thrown on line 86?

ALine 92 will not execute
BThe connection will not be retrieved in line 85
CThe resource connection will not be closed on line 88
DThe 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:
13import java.io.*;14class Food implements Serializable{int good = 3;}15class Fruit extends Food{int juice = 5;}16public class Banana extends Fruit{17int yellow = 4;18public static void main(String[] args){19Banana b = new Banana();20b.serializeBanana(b);21b2 = b.deserializeBanana();22System.out.println("restore" + b2.yellow + b2.juice + b2.good);23}24//more Banana methods go here25

What is the result?

Arestore 400
Brestore 403
Crestore 453
DCompilation fails
EAn exception is thrown at runtime



Answer : C


Given :12 System.out.format("Pi is approximately %d", Math.PI);

What is the result?

ACompilation fails
BPi is approximately 3.
CPi is approximately 3.141593
DAn exception is thrown at runtime



Answer : D

11public class Yikes{1213public static void go(Long n){System.out.println("Long ");}14public static void go(Short n){System.out.println("Short ");}15public static void go(int n){System.out.println("int ");}16public static void main(String[] args){17short y = 6;18long z = 7;19go(y);20go(z);21}22}


What is the result?

Aint Long
BShort Long
CCompilation fails
DAn exception is thrown at runtime

Answer : A



Given this method in a class:
21public String toString(){22StringBuffer buffer = new StringBuffer();23buffer.append('<');24buffer.append(this.name);25buffer.append('>');26return buffer.toString();27}


Which statement is true?


AThis code is NOT thread-safe
BThe programmer can replace StringBuffer with StringBuilder with no other changes
CThis code will perform poorly.For better performance,the code should be rewritten:return "<" + this.name + ">";
DThis code will perform well and converting the code to use StringBuffer will not enchange the performance



Answer: B



Given :

33Date d = new Date(0);34String ds = "December 15, 2004";35// insert code here36try{37d = df.parse(ds);38}39catch(ParseException e){40System.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?

A35.DateFormat df = DateFormat.getDateFormat();
42.d.setTime((60*60*24) + d.getTime());
B35.DateFormat df = DateFormat.getDateInstance();
42.d.setTime((1000*60*60*24) + d.getTime());
C35.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 :
12NumberFormat nf = NumberFormat.getInstance();13nf.setMaxinumFractionDigits(4);14nf.setMininumFractionDigits(2);15String a = nf.format(3.1415926);16String b = nf.format(2);

Which two statements are true about the result if the locale is Locale.US?(Choose two)


AThe value of b is 2
BThe value of a is 3.14
CThe value of b is 2.00
DThe value of a is 3.141
EThe value of a is 3.1415
FThe value of a is 3.1416
GThe value of b is 2.0000.


Answer: C F


1import java.util.*;2public class Old{3public static Object get0(List list){4return list.get(0);5}6}

Which three will compile successfully?(Choose three)


AObject o = Old.get0(new LinkedList());
BObject o = Old.get0(new LinkedList<?>());
CString s = Old.get0(new LinkedList<String>());
DObject o = Old.get0(new LinkedList<Object>());
EString s = (String)Old.get0(new LinkedList<String>());
F


Answer: A D E
页: [1]
查看完整版本: SCJP认证试题(九)