Page 114 - computer science (868) class 11
P. 114
5.6.1 Corresponding Wrapper Classes for Each Primitive Type
The wrapper class is used to convert the primitive data type to its object and vice versa. A wrapper class is required to:
• store the primitive data type in object.
• convert String to primitive data type and vice versa.
Each primitive data type has its own wrapper class. Some of the wrapper class lists are as follows.
Primitive Data Type Wrapper Class
byte Byte
short Short
int Integer
long Long
float Float
double Double
boolean Boolean
char Character
Let us take the following example:
class wrapper_class
{
public static void main()
{
Integer int_var = 100;
Double double_var = 125.95;
Character char_var = 'a';
Float float_var = 34.56f;
System.out.println("Integer Variable" +int_var);
System.out.println("Double Variable" +double_var);
System.out.println("Character Variable" +char_var);
System.out.println("Float Variable" +float_var);
}
}
The output of the preceding program is as follows:
5.7 CLASS AS TYPE OF THE OBJECT
A Java program is made up of classes. And each class is made up of some attributes (data members), that are
predefined data types. While creating an object of a class, we are basically defining a variable which has the size of
the total bytes of the predefined data types. A user-defined data type is a derived data type depending on some
existing data types. Thus, when an object is created, it consists of all the data members of the class, which are all
individual primitive data members. So, the instance of the class, which is known as an object, has its size equal to
the total size of all the data members. As a result, we can define class as a type of object as well as a mechanism of
a user-defined type.
112112 Touchpad Computer Science-XI

