# Answer to Question #60063 in Java | JSP | JSF for MB Knudsen

Question #60063

Which of the following methods will compile without error?

public int add(List<? extends Number> list) {

int sum = 0;

for (Integer i : list) sum += i;

return sum;

}

public int add(List<? super Integer> list) {

int sum = 0;

for (Integer i : list) sum += i;

return sum;

}

public int add(List<? extends Integer> list) {

int sum = 0;

for (Integer i : list) sum += i;

return sum;

}

public int add(List<?> list) {

int sum = 0;

for (Integer i : list) sum += i;

return sum;

}

public int add(List<? extends Number> list) {

int sum = 0;

for (Integer i : list) sum += i;

return sum;

}

public int add(List<? super Integer> list) {

int sum = 0;

for (Integer i : list) sum += i;

return sum;

}

public int add(List<? extends Integer> list) {

int sum = 0;

for (Integer i : list) sum += i;

return sum;

}

public int add(List<?> list) {

int sum = 0;

for (Integer i : list) sum += i;

return sum;

}

Expert's answer

public int add(List<? extends Integer> list) {

int sum = 0;

for (Integer i : list) sum += i;

return sum;

}

Because only in this method is a valid class cast

int sum = 0;

for (Integer i : list) sum += i;

return sum;

}

Because only in this method is a valid class cast

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment