Disable ads (and more) with a membership for a one time $2.99 payment
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
The List must be of type Fruit
Any of the listed types can be used
The correct answer is: 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.