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 allows List<? super Apple> to safely add an Apple object?

  1. It specifies the list must accept Apple as a lower bound

  2. It guarantees the list contains only Apple objects

  3. It allows any type as long as it's a base type of Apple

  4. It automatically casts added objects to Apple

The correct answer is: It allows any type as long as it's a base type of Apple

Generics in Java use the term "super" to represent a lower bound. In this context, "? super Apple" means that the list can accept any type that is a superclass of Apple. So, option C is correct because it allows for any type as long as it is a base type of Apple. Option A is incorrect because it specifies a lower bound, not an upper bound. Option B is incorrect because it guarantees only that the list contains Apple objects, not necessarily that only Apple objects can be added. Option D is incorrect because it does not automatically cast added objects to Apple.