Page 74 - CA_Blue( J )_Class9
P. 74

You will get the following output:



















                  4.7.2 Explicit Type Conversion
                  In Explicit Type conversion, we can assign a value of larger data type to a smaller data type. It is a process of
                  narrowing. This is useful for incompatible data types where automatic conversion is not feasible. It requires user’s
                  intervention. Here, target-type specifies the desired type to convert the specified value to.


                            double          float         long           int          short         byte



                   Program 16     Write a program to demonstrate explicit conversion.

                     1  class explicite_conversion

                     2  {
                     3      public static void main()

                     4      {
                     5          double d=550.54;

                     6          long l=(long)d;
                     7          int i= (int)l;
                     8          System.out.println("Double type value: "+d);

                     9          System.out.println("Long type value: "+l);

                    10          System.out.println("Integer type value: "+i);
                    11      }
                    12  }

                  You will get the following output:


















                    72    Touchpad Computer Applications-IX
   69   70   71   72   73   74   75   76   77   78   79