← 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")));
}
}
- A.23
- B.5
- C.Compile error: List<?> cannot hold Integers
- 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 →