QUESTION 42
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
Solution : C
실행결과
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at java.lang.Integer.compareTo(Integer.java:37)
at java.util.Arrays.mergeSort(Arrays.java:1144)
at java.util.Arrays.sort(Arrays.java:1079)
at main(Main.java:29)
해석 : "String 이 담겨있기 때문에 정수형으로 바꿀 수 없다" 라는 오류메시지.
'자격증 > OCJP_ExamA' 카테고리의 다른 글
QUESTION 44 (0) | 2018.07.08 |
---|---|
QUESTION 43 (0) | 2018.07.08 |
QUESTION 41 (0) | 2018.07.08 |
QUESTION 40 (0) | 2018.07.08 |
QUESTION 39 (0) | 2018.07.08 |
#IT #먹방 #전자기기 #일상
#개발 #일상