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

Prepare for your Java exam with our ultimate quiz based on 'Thinking in Java'. Engage with expertly crafted questions that enhance your learning process. Perfect for Java enthusiasts looking to solidify their knowledge!

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