Monday, July 5, 2010

Type Casting

The process of converting one data type to another is called casting. We must convert the values to be stored by
proceeding it with the type name in parentheses.

Syntax
type variabel1= (type) variable2

Example
int m=50;
byte n= (byte)m;
long count=(long) m;

Automatic Conversion:

Java does the conversion of the assigned values automatically. This is known as automatic type conversion.
Automatic type conversion is possible only if the destination type has enough precision to store the source
value.

The process of assigning a smaller type to a larger one is known as widening or promotion.Assigning a larger type to a smaller one is known as narrowing. Narrowing may results in loss of information.

No comments:

Post a Comment