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

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

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


What restriction does using <? super T> in a generic class or method impose?

  1. The class or method cannot accept arguments of type T

  2. Objects of T or its superclasses can be added to a collection

  3. The class or method cannot return objects of general types

  4. Only objects of type Object can be used with the class or method

The correct answer is: Objects of T or its superclasses can be added to a collection

When using a generic class or method with the <? super T> restriction, objects of type T or any of its superclasses can be added to a collection. This means that objects of more specific types cannot be added, but it allows for a wider range of objects to be accepted. Options A, C, and D are incorrect because they imply more limitations on the type of objects that can be used, while option B provides the most accurate description of the restriction imposed by <? super T>.