Mastering Java: The Ultimate Quiz for 'Thinking in Java

Image Description

Question: 1 / 510

Why are wrapper classes used in Java generics?

To allow primitive types as type parameters

Wrapper classes are used in Java generics to allow primitive types as type parameters. This is because generics only accept objects as type parameters, so primitive types cannot be used directly. Wrapper classes, such as Integer and Double, wrap around the primitive types and allow them to be used in generics. Additionally, using primitive types in generics would result in auto-boxing and unboxing, which can cause performance issues. Therefore, options B, C, and D are incorrect as they either do not mention the main purpose of wrapper classes in generics or they suggest incorrect reasons for using them.

Get further explanation with Examzify DeepDiveBeta

For type safety and elimination of casts

To enhance performance

To enable collections to work with primitives

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy