🎙 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 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()));
    }
}
  1. A.false
  2. B.true
  3. C.Compile error
  4. 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 →