Mastering Java: The Ultimate Quiz for 'Thinking in Java' 2026 - Free Java Programming Practice Questions and Study Guide

Question: 1 / 510

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

You cannot add any object to the List

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.

Get further explanation with Examzify DeepDiveBeta

You can only add Fruit objects to the List

You can add any subtype of Fruit to the List

No restrictions, any object can be added to the List

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy