What restriction does a List<? extends Fruit> impose?

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.

A List<? extends Fruit> imposes the restriction that only objects of type Fruit or its subtypes can be added to the list. Option B and C suggest that only objects of type Fruit can be added to the list, but this is incorrect as subtypes of Fruit are also allowed. Option D states that there are no restrictions, but this is incorrect as the list can only contain objects of type Fruit or its subtypes. Option A is the correct answer as it accurately states that no objects can be added to the list, regardless of whether they are of type Fruit or its subtypes. This is because when using the wildcard ? extends Fruit, the compiler cannot determine the specific type of objects that can be added to the list, so it prevents any objects from being added to avoid potential type errors.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy