SCJP真题库更新19

QUESTION 91

Given a method that must ensure that its parameter is not null:

 

What, inserted at line 12, is the appropriate way to handle a null value?

A. assert value = = null;

B. assert value != null, "value is null";

C. if (value = = null) {

throw new AssertionException("value is null");

}

D. if (value = = null) {

throw  new IllegalArgumentException("value is null");

}

 

 

Answer: ( D )

A      不要用断言对公共方法的参数进行判断

B      同上

C     没有AssertionException这个类; AssertionError继承自Error,处理和捕获 error是没有意义的

D      OK 抛出参数错误的异常.

 

 

QUESTION 92

Place the correct Code in the Code Sample to achieve the expected results.

Expected results:

Output: 1 2 4 8 16 32

Code Sample

 

 Answer: (  )

for (int x : y){

 

QUESTION 93

Given:

 

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 )

 

QUESTION 94

Given:

 

Which statement is true if a ResourceException 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 throw an exception to its caller.

 

 

Answer: ( C )

 

QUESTION 95

Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java serialization and given:

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 )

 

你可能感兴趣的:(scjp,真题)