🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Java Generics: all 10 questions

Quiz: Java Generics · Question 9 of 10

What does this print? (code)

What does this print?

import java.util.*;
public class Main {
    static int count(List<?> list) { return list.size(); }
    public static void main(String[] args) {
        System.out.println(count(List.of(1, 2)) + count(List.of("a", "b", "c")));
    }
}
  1. A.23
  2. B.5
  3. C.Compile error: List<?> cannot hold Integers
  4. D.2
Answer & explanation

Correct answer: 5

List<?> accepts a list of any type. 2 + 3 = 5.

Can you get the rest right without peeking?

Take the timed Quiz: Java Generics quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →