What types of objects can List<?> accept via its add method?

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<?> can accept objects of any type via its add method. This means that the specific type of element being added to the list does not need to be specified. Therefore, options A and B are incorrect.

Option C, which states that the list can only accept null, is also incorrect. While it is true that null is a valid object and can be added to a list, it is not the only type of object that can be added using the add method.

Option D is incorrect because a List<?> can accept objects of the wildcard type as well as any of its subclasses. So it is not limited to accepting only objects of the base class of the wildcard type.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy