Copyright Tarena Corporation,2008.All rights reserved
Which code, inserted at line 16, will cause
a
java.lang.ClassCastException?
A. Alpha
a
= x;
B.
Foo f= (Delta)x;
C.
Foo f= (Alpha)x;
D. Beta b = (Beta)(Alpha)x;
Answer: B
Question 5
Given:
23. Object [] myObjects = {
24. new I nteger(12),
25. new String( " foo " ),
26. new I nteger(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
Question 6
Given:
11.
public static void parse(String str) {
12. try {
13. float f= Float.parseFloat(str);
14. } catch (NumberFormatException nfe) {
15. f=
0;
16. } finally {
17. System.out.println(f);
18. }
19. }
20. public static void main(String[] args) {
21. parse( " invalid "
);
22. }
What is the result?