Wednesday 22 January 2020

What is wrapper class in Java? tccicomputercoaching.com


Wrapper classes provide a way to use primitive data types (int, boolean, etc..) as objects.


The eight primitive data types byte, short, int, long, float, double, char and boolean are not objects, Wrapper classes are used for converting primitive data types into objects, like int to Integer etc.

For example , The Integer is a wrapper class of int primitive type.

The wrapper objects hold much more memory compared to primitive types. So use primitive types when you need efficiency and use wrapper class when you need objects instead of primitive types.

public class test{

public static void main(String args[]){

//Converting int primitive into Integer object

int a=100;

Integer obj=Integer.valueOf(a);

System.out.println(a+ " "+ obj);

}

}

Output:

100 100

TCCI can help student to grasp such an important topics very well.

We have located in Bopal and Satellite in Ahmedabad.

To inquire Call us @ 98256 18292.

Visit us @tccicomputercoaching.com

No comments:

Post a Comment