πŸ“Š JAVA
Q. What will be the output of the following code
Code:
import java.util.ArrayList;
import java.util.List;

public class MyClass {
public static void main (String args[])
{
List<Integer> list=new ArrayList<Integer>();
list.add(2);
list.add(3);
System.out.println(sum(list));

}
public static double sum(List<? extends Number> list)
{
double sum=0;
for(Number num:list)
{
sum+=num.doubleValue();
}
return sum;
}
}
  • (A) 5.0
  • (B) 5
  • (C) Runtime exception
  • (D) Compile time exception
πŸ’¬ Discuss
βœ… Correct Answer: (A) 5.0

You must be Logged in to update hint/solution

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
325
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Pradeep Sikarwar
Publisher
πŸ“ˆ
89%
Success Rate