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 is true about using bounded generics in Java?

  1. They restrict the types that can be used as type arguments

  2. They make the code less type-safe

  3. They allow the code to operate on any type

  4. They are not compatible with collections

The correct answer is: They restrict the types that can be used as type arguments

Using bounded generic in Java means a type parameter is defined and restricted to accept only certain data types. As a result, options B and C can be eliminated since it contradicts the true nature of bounded generics. Option D is incorrect because bounded generics are compatible with collections, in fact, they are commonly used in collections to ensure the type safety of the data stored in the collection. Therefore, the only correct statement is that bounded generics restrict the types that can be used as type arguments, making option A the correct choice.