Type Casting.
Type Casting.
R COLLEGE OF
SCIENCE,KOVVUR
CLASS :IIB.SC(M.P.CS,M.S.CS,M.C.CS)
Type casting is a process to convert a value of one data type to another data type.
There is a need to store a value of one type into a variable of another type. We must
cast the value to be stored by preceding it with the type name in parentheses.
Example:-
1. int a=125;
byte b;
b=a;//compile time error. Here conversion is required.
b=(int)a;
2. int x=97;
char ch=(char)x;
System.out.println(ch); prints ‘a’. Here conversion is done by the programmer.