Java MCQ: Which of the following is a wrapper class in Java?
Answer:
Explanation:
In Java, a wrapper class is an object representation of a primitive data type. The Integer
class is a wrapper class for the primitive data type int
. Wrapper classes provide a way to use primitive data types as objects, allowing them to be used in collections that require objects, such as ArrayList
or HashMap
.
Other examples of wrapper classes include Float
for float
, Boolean
for boolean
, and Double
for double
. These classes provide methods for converting between the primitive type and the object type, as well as additional functionality.
Understanding wrapper classes is important for situations where primitives need to be treated as objects, such as in collections or when using generic types.
Reference links:
https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html