浏览 168 次
|
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
|---|---|
| 作者 | 正文 |
|
最后更新时间:2008-04-28
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 答案是C,我觉得应该是b, 声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
|
| 返回顶楼 | |
|
最后更新时间:2008-04-29
看JDK 源码。
Arrays.sort : ... ((Comparable) dest[j-1]).compareTo(dest[j])>0 ... Iteger.compareTo: ... public int compareTo(Integer anotherInteger) ... 抛出ClassCastException. |
|
| 返回顶楼 | |
|
最后更新时间:2008-04-30
懂了,但是为什么运行的时候抛出的是ArrayIndexOutOfBoundsException?
|
|
| 返回顶楼 | |


