Oracle
1Z0-851 · Question #1
1Z0-851 Question #1: Real Exam Question with Answer & Explanation
Sign in or unlock 1Z0-851 to reveal the answer and full explanation for question #1. The question stem and answer options stay visible for context.
Question
Given a pre-generics implementation of a method: 11. public static int sum(List list) { 12. int sum = 0; 13. for ( Iterator iter = list.iterator(); iter.hasNext(); ) { 14. int i = ((Integer)iter.next()).intValue(); 15. sum += i; 16. } 17. return sum; 18. } What three changes allow the class to be used with generics and avoid an unchecked warning? (Choose three.)
Options
- ARemove line 14.
- BReplace line 14 with "int i = iter.next();".
- CReplace line 13 with "for (int i : intList) {".
- DReplace line 13 with "for (Iterator iter : intList) {".
- EReplace the method declaration with "sum(List<int> intList)".
- FReplace the method declaration with "sum(List<Integer> intList)".
Unlock 1Z0-851 to see the answer
You've previewed enough free 1Z0-851 questions. Unlock 1Z0-851 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.