`
miraclerz
  • 浏览: 97270 次
社区版块
存档分类
最新评论

SCJP真题库更新21

    博客分类:
  • SCJP
阅读更多

QUESTION 101

Given:

 

What creates the appropriate 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 )

转换成求加1天以后改日期的毫秒数,再调用setTime()设置时间。

 

 

 

QUESTION 102

Given:

 

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 )

使用NumberFormat类的getInstance()工厂方法会得到它的具体子类DecimalFormat的对象,默认情况下此DecimalFormat的相关属性如下:

²  使用当前默认语言环境的Locale

²  最大小数位数maximumFractionDigits3

²  最小小数位数minimumFractionDigits0

²  最大整数位数maximumIntegerDigits2147483647

²  最小整数位数minimumIntegerDigits1

²  舍入模式是RoundingMode.HALF_EVENRoundingMode.HALF_EVEN是向最接近数字方向舍入的舍入模式,如果与两个相邻数字的距离相等,则向相邻的偶数舍入。例如:

u  示例:

²  输入数字

²  使用 HALF_EVEN 舍入模式
将输入数字舍入为一位数

²  5.5

²  6

²  2.5

²  2

²  1.6

²  2

²  1.1

²  1

²  1.0

²  1

²  -1.0

²  -1

²  -1.1

²  -1

²  -1.6

²  -2

²  -2.5

²  -2

²  -5.5

²  -6

 

 

QUESTION 103

Place the correct description of the compiler output on the code fragment to be inserted at line 4 and 5. The same compiler output may be used more than once.

Answer: (  )

 

 

 

 

 

 

QUESTION 104

Given:

 

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>()); 

 

 

 

Answer: ( A, D, E )

B 错误 <?>不能用于实参传递,只能用于形参定义。

C 错误 get0()方法的回传值是Object, 因此不可赋值给String

此题的答案ADE选项的程式代码虽然能够编译通过,但是运行时会抛出java.lang.IndexOutOfBoundsException异常。

 

 

QUESTION 105

Exhibit:

 

 

Which statement is true about the set variable on line 12? 

A. The set variable contains all six elements from the coll collection, and the order is guaranteed to be preserved.

B. The set variable contains only three elements from the coll collection, and the order is guaranteed to be preserved.

C. The set variable contains all six elements from the coll collection, but the order is NOT guaranteed to be preserved.

D. The set variable contains only three elements from the coll collection, but the order is NOT guaranteed to be preserved.

 

 

Answer: ( D )

枚举类型的hashCode()方法和equals()方法实现如下:

    /**

     * Returns true if the specified object is equal to this

     * enum constant.

     *

     * @param other the object to be compared for equality with this object.

     * @return  true if the specified object is equal to this

     *          enum constant.

     */

    public final boolean equals(Object other) {

        return this==other;

    }

 

    /**

     * Returns a hash code for this enum constant.

     *

     * @return a hash code for this enum constant.

     */

    public final int hashCode() {

        return super.hashCode();

    }

super指的就是Object类,调用Object类提供的hashCode方法来直接返回该对象的内存地址值。

Set中不能存放重复的元素(使用hashCode方法和equals方法双重判断),但是不保证所存放元素的顺序

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics