Question 11
Given:
23. Object [] myObjects = {
24. new integer(12),
25. new String(”foo”),
26. new integer(5),
27. new Boolean(true)
28. };
29. Arrays.sort(myObjects);
30. for( int i=0; i<myObjects.length; i++) {
31. System.out.print(myObjects[i].toString());
32. System.out.print(” “);
33. }
What is the result?
A. Compilation fails due to an error in line 23.
B. Compilation fails due to an error in line 29.
C. A ClassCastException occurs in line 29.
D. A ClassCastException occurs in line 31.
E. The value of all four objects prints in natural order.
Answer: C
为什么呢??
Given:
23. Object [] myObjects = {
24. new integer(12),
25. new String(”foo”),
26. new integer(5),
27. new Boolean(true)
28. };
29. Arrays.sort(myObjects);
30. for( int i=0; i<myObjects.length; i++) {
31. System.out.print(myObjects[i].toString());
32. System.out.print(” “);
33. }
What is the result?
A. Compilation fails due to an error in line 23.
B. Compilation fails due to an error in line 29.
C. A ClassCastException occurs in line 29.
D. A ClassCastException occurs in line 31.
E. The value of all four objects prints in natural order.
Answer: C
为什么呢??
解决方案 »
- java新手求助
- java 一个正则表达式
- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Prio
- NEW了一个frame对象,为啥不能关闭?
- 一个奇怪的新手问题。大家麻烦解答下
- RTTI的问题
- 在java applet中的URL类要有哪个引用啊
- 我要通过jdbc连接远程informix数据库,请问远程的数据库应该如何设置? 程序报错INFORMIXSERVER has to be specified
- jdk1.4是否支持application播放声音?
- 初学java我该看什么书
- 求THINKING IN JAVA 4
- 这个do-while语句为什么条件没有满足循环却停止了?
字符串不能格式化为INTEGER会抛出NUMBERFORMATEXCEPITON异常
a - 要排序的数组
抛出:
ClassCastException - 如果数组包含不可相互比较的 的元素(例如,字符串和整数)。
学习了!!