What is the result of compilation and execution of the following code?

public class Test {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<Integer>();
        list.add(100);
        list.add(200);
        list.add(300);
        list.add(200);
        Set<Number> set = new HashSet<Integer>(list);
        System.out.println(set.size());
        } 
}
Explanation
Generic class HashSet<Integer> is not a subtype of Set<Number>
More here https://docs.oracle.com/javase/tutorial/java/generics/inheritance.html

Follow CodeGalaxy

Mobile Beta

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