What will happen during the following code execution?

import java.util.*;
public class Test {
    public static void main(String[] args) {
        List a = new ArrayList<Double>();// 4
        a.add("1.5");// 5
        List<Double> b = new ArrayList();// 6
        b.add("1.5");// 7
        System.out.println(a + " " + b);
Compilation error occurs in the seventh line, because only elements of Double type and derived from it can be added to the "b" collection. Elements of any type can be added to "a" collection, so parameterized type Double is stepped up to Object.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Sign Up Now
or Subscribe for future quizzes