Type conversion in Java
Posted by damuchinni on March 15, 2009
The type conversion in java of two types.
a)Automatic type conversion
b)Casting
Automatic type conversion: When one type of data is assigned to another type of variable an automatic type conversion will take place.
Conditions 1)The two types are compatible 2)The destination type is larger than the source type.
Ex:
int x=10;
byte y=2;
x=y; byte to int automatic conversion.
Casting: It is used to perform conversion between incompatible types.
Syntax: (Target_type)value
Target type specifies the desired type of convert the specified value to.
Ex:
Int i=257;
Byte b;
B=(byte)i; //now b value is 1.
Leave a comment