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

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!

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