Ace Java 2025: Rock Your 'Thinking in Java' Challenge!

Image Description

Question: 1 / 510

What is required to add an Apple object to a List in the example provided?

The List must be of type Apple

The List must use a wildcard extending Apple

To add an Apple object to a List, the List must use a wildcard extending Apple. This is because Lists are type-specific and can only contain objects of the specified type or its subclasses. Option A is incorrect because it limits the List to only contain objects of type Apple, but not its subclasses. Option C is incorrect because it would not allow for other types of Fruit besides Apple to be added to the List. Option D is incorrect because it does not specify the type, which would result in a compilation error. Therefore, the only correct option is B, as it allows for any subclass of Apple to be added to the List.

Get further explanation with Examzify DeepDiveBeta

The List must be of type Fruit

Any of the listed types can be used

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy