Explain wrappers classes in java with suitable example
Answers
Answered by
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);
}}
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
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
Math,
7 months ago
Social Sciences,
7 months ago
Science,
7 months ago
Biology,
1 year ago
Math,
1 year ago