by Dinesh Thakur

Type casting is the process of "casting"(Casting mean ‘conversion’ of value to another type) of value to one type to another type of variable.

Here is the Java Example for Type Casting:

class  TypeCasting

{
            public  static  void  main  (String  args[ ] )
            {
                        int   i=65;
                        byte b;
                        double   d;
                        char    c;
                        short   s;
                        float     f;
                        b=  (byte) i;
                        System.out.println("Byte  of  Integer  "+i+  "  is  "+b);
                        f= (float)i;
                        System.out.println ("Float  of  Integer  "+i+  "  is  "+f);
                        c=(char) i;
                        System.out.println("Char  of  Integer  "+i+  "  is  "+c);
                        f=(float)12.889775;
                        d=(double)f;
                        System.out.println("Double of  Float    "+f+  "  is  "+d);
                        b=(byte)f;
                        System.out.println("Byte  of  Float  "+f+  "  is  "+b);
                        i=(int)f;
                        System.out.println("Int  of  Float  "+f+  "  is  "+i);
                        c='b';
                        d=(double)c;
                        System.out.println("Double  of  Char  "+c+  "  is  "+d);
                        b=(byte)c;
                        System.out.println("Byte  of  Char  "+c+  "  is  "+b);
                        i=(int)c;
                        System.out.println("Int  of  Char  "+c+  " is " +i);
            }
}

Type Casting in Java