Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Dive into the depths of Java with our quiz based on "Thinking in Java, Fourth Edition" by Bruce Eckel. Test your knowledge, solidify concepts, and prepare for certification with challenging questions and insightful feedback.

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


How do you assign a List<Apple> to a List<? super Apple> variable?

  1. Using direct assignment without any casts

  2. By casting List<Apple> to List<? super Apple>

  3. Using generic wildcard as method parameter

  4. It's not possible to assign List<Apple> to List<? super Apple>

The correct answer is: Using generic wildcard as method parameter

The question is asking how to assign a List of type Apple to a List that can contain either Apple or one of its superclasses (i.e. a List of type Fruit, for example). Option A and D are incorrect because direct assignment and casting are not involved here. Option B is incorrect because you do not need to cast the List of Apple to assign it to a List of wildcard type. Option C is the correct answer because using a generic wildcard as a method parameter allows us to specify that the List can contain either an Apple or one of its superclasses. This makes it possible to assign a List of Apple objects to a List of any supertype of Apple.