Computer Science, asked by sunilpotdar8941, 1 year ago

Explain wrappers classes in java with suitable example

Answers

Answered by golu00145
3
A Wrapper class is a class whose object wraps or contains a primitive data types. When we create an object to a wrapper class, it contains a field and in this field, we can store a primitive data types. In other words, we can wrap a primitive value into a wrapper class object.
public class WrapperExample1{
public static void main(String args[]){
//Converting int into Integer
int a=20;
Integer i=Integer.valueOf(a);//converting int into Integer
Integer j=a;//autoboxing, now compiler will write Integer.valueOf(a) internally

System.out.println(a+" "+i+" "+j);
}}
Answered by amitaagarwal4827
0

Answer:

wrapper classes convert primitive data types in two objects objects are needed if we wish to modify the arguments passed into a method because it might have data types are passed by value.

the classes in Java. util package handles only objects and hence wrapper classes helps in this case also.

Similar questions