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

Disable ads (and more) with a premium pass for a one time $4.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.

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.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy