What is the result of compilation and execution of the following program:

import java.util.*;

class Main {
    public static void main(String[] args) {
        List<?> list = new ArrayList<String>();
        list.add("a");
        System.out.println(list.get(0));
    }
}
Explanation
When you have an object of generic class defined with a wildcard <?>, you can't call methods, that take arguments of type-parameter. The only exception from this rule is passing the value null.
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback