← Quiz: Java Generics: all 10 questions
Quiz: Java Generics · Question 6 of 10
What does this print? (code)
What does this print?
import java.util.*;
public class Main {
public static void main(String[] args) {
List<String> a = new ArrayList<>();
List<Double> b = new ArrayList<>();
System.out.println(a.getClass().equals(b.getClass()));
}
}
- A.false
- B.true
- C.Compile error
- D.ClassCastException
Answer & explanation
Correct answer: true
Type erasure removes the type arguments, so both are just ArrayList at runtime.
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 →