Type Casting in java

Type Casting

            Forcefully conversion of one data type into another is known as type casting.

Following are the possible reasons of generating errors related to typecasting.

Syntax

 

<target variable>=(target data type )<source variable>;
  1. Number of bytes of target variable is less than the number of bytes of source variable.
  2. Source and target variable are of different groups.
  3. boolean cannot be type cast to other data type and vice versa.

class Example1

{

     public static void main (String args[ ])

{

            short s;

            int  i = 12;

            s=i;

System.out.println(s);

System.out.println(i);

}

}

Leave a Reply

Your email address will not be published. Required fields are marked *