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

Home > Java Programming > Collections > Questions and Answers

Q: Given:
1. public static Collection get() {
2. Collection sorted = new LinkedList();
3. sorted.add("B"); sorted.add("C"); sorted.add("A");
4. return sorted;
5. }
6. public static void main(String[] args) {
7. for (Object obj: get()) {
8. System.out.print(obj + ", ");
9. }
10. }
What is the result?
A. A, B, C B. B, C, A
C. Compilation fails. D. The code runs with no output.
E. An exception is thrown at runtime.

Answer and Explanation

Answer:B, C, A

Explanation:
In LinkedList however you add, it will display as it is. So option B is correct. 

Comment on this Question

Name:

Loading...




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