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

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

Want to excel in Java? Test your knowledge with our ultimate quiz based on 'Thinking in Java'. Engage with multiple-choice questions and in-depth explanations. Boost your understanding and prepare for your exam with confidence.

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.


Why can a generic class not directly inherit from its generic type parameter in Java?

  1. Because generics in Java use type erasure

  2. Because it causes a compilation error

  3. Because it violates Java's type safety

  4. Because of Java's inheritance rules

The correct answer is: Because of Java's inheritance rules

When a class extends a generic class, it must specify a concrete type for the generic parameter. In this case, if the generic class were to directly inherit from its generic type parameter, it would create a circular dependency and result in a compilation error. Additionally, this inheritance scenario would not make sense from a design standpoint as it would essentially create an infinite loop. Therefore, Java's inheritance rules prohibit a generic class from directly inheriting from its generic type parameter. Choices A and C are incorrect because generics in Java use type erasure, meaning that the generic type information is removed during compilation and replaced with Object as the type. Choice B is incorrect because it is a generic class inheriting from its generic type parameter that would cause a compilation error, not the other way around.