Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
public class AddStrings<T> {
    String add(Collection<Integer> obj) {
        String result = "";
        for (Object o : obj)
            result += o;
        return result;
    }
    public static void main(String args[]) {
        List<String> numbers = Arrays.asList("1", "2", "3");
        System.out.println("Sum = " + new AddStrings().add(numbers));
    }
}


Sum = 6
Sum = 123
Compilation Error
Runtime Error

Doubts

Problems

Topic: Why Collections Are Generic In Java?

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App