Which three changes must be made to the method sum to use generics?

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. }
Which three changes must be made to the method sum to use generics? (Choose three.)

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. }
Which three changes must be made to the method sum to use generics? (Choose three.)

A.
replace line 14 with “int i = iter.next();”

B.
replace line 13 with “for (Iterator iter : intList) {“

C.
replace the method declaration with “sum(List<int> intList)”

D.
remove line 14

E.
replace the method declaration with “sum(List<Integer> intList)”

F.
replace line 13 with “for (int i : intList) {“



Leave a Reply 0

Your email address will not be published. Required fields are marked *