Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

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.

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


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

  1. Objects of any type

  2. Only objects of the specified wildcard type

  3. Only null

  4. Only objects of the base class of the wildcard type

The correct answer is: Only null

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.