Welcome Guest | Sign in | Register
Collections - Discussion Page For Q.2575 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Collections > Questions and Answers

Q: 1. Object [] myObjects = {
2. new Integer(12),
3.  new String("foo"),
4.      new Integer(5),
5.      new Boolean(true)
6. };
7. Arrays.sort(myObjects);
8. for(int i=0; i9. System.out.print(myObjects[i].toString());
10  System.out.print(" ");
11. }
What is the result?
A. Compilation fails due to an error in line 1. B. Compilation fails due to an error in line 7.
C. A ClassCastException occurs in line 7. D. A ClassCastException occurs in line 9.
E. The value of all four objects prints in natural order.

Answer and Explanation

Answer:A ClassCastException occurs in line 7.

Explanation:
Whenever you call Arrays.sort() method on some object then that class should implement Comparable interface. If not it will throw exception.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.