Mastering Java 2025 – 400 Free Practice Questions to Pass the 'Thinking in Java' Exam

Image Description

Question: 1 / 510

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

Using direct assignment without any casts

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

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.

Get further explanation with Examzify DeepDiveBeta

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

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy