Computer Science, asked by kusum2918, 7 months ago

Why do we need wrapper classes at all when we already have various primitive data types to hold in process values of different types?​

Answers

Answered by Anonymous
0

\huge{\underline{\boxed{\sf{\red{\mathfrak{Answer-}}}}}}

Major reasons for having wrapper classes are :

  • Java is an object oriented language where everything is used as objects. The wrapper classes enable a primitive value to be used as objects. As objects they can be used with all types of classes and their methods.

  • Wrapper classes provide many ready-to-use utility methods such as converting a string having primitive type value to equivalent primitive form e.g., "10" can be converted to integer 10 using wrapper class method; and many other functions.

  • Primitive data types are passed by value but objects are passed by reference. Wrapper classes facility passing primitives by reference, as an argument to a method, if so required.

  • There are some other reasons that make wrapper classes useful in advanced Java (such as with data structures and some frameworks etc.)

_____________________

\Large{\mathfrak{\red{Important-}}}

The wrapper classes are final, i.e., once assigned a value, the value of a wrapper class cannot be changed. Java does this to ensure uniform capabilities across all instances.

_____________________

Similar questions
Math, 11 months ago