A generic method for adding all numbers in a collection

Question | Dec 28, 2017 | nextptr 

The given code defines an ArrayList< Integer > and fills it with few values:

ArrayList<Integer> list = new ArrayList<>();

// fill the list    

We have defined a method that returns sum of all values of a given collection. The collection parameter c has to be generic to accept any kind of Collection of Number objects. You have to tell what is the correct parameter type of method add from given choices.

double add( ______  c ) {   
     double sum = 0;
     for(Number num : c)
       sum += num.doubleValue();

     return sum;

When add is called on list, it returns 300.0:

System.out.println(add(list)); // 300.0

Which one of the following choices can replace ______ above?