What allows List<? super Apple> to safely add an Apple object?

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!

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.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy