Page 146 - ComputerScience_Class_11
P. 146

Primitive Data Type                Wrapper Class
                                   long                            Long
                                   float                           Float
                                   double                          Double
                                   boolean                         Boolean
                                   char                            Character


                Program 4      Write a program to demonstrate the use of wrapper classes in Java.

                1      class wrapper_class

                2      {

                3          public static void main(String[] args)
                4          {

                5              Integer int_var = 100;

                6              Double double_var = 125.95;
                7              Character char_var = 'a';

                8              Float float_var = 34.56f;

                9              System.out.println("Integer Variable: " +int_var);

                10             System.out.println("Double Variable: " +double_var);
                11             System.out.println("Character Variable: " +char_var);

                12             System.out.println("Float Variable: " +float_var);

                13         }
                14     }

              The output of the preceding program is as follows:

                      BlueJ: Terminal Window - Java

                   Options

                  Integer Variable: 100
                  Double Variable: 125.95
                  Character Variable: a
                  Float Variable: 34.56



                   6.7 CLASS AS TYPE OF THE OBJECT
              In Java, when an object of a class is created, it contains all the data members defined in that class. These data members
              may include both primitive data types and objects. The instance of a class is known as an object and the size of the
              object is equal to the total size of all its data members. Therefore, a class defines the structure and size of its objects
              and thus a class can be considered as the type of the object.






                  144  Touchpad Computer Science (Ver. 3.0)-XI
   141   142   143   144   145   146   147   148   149   150   151