public class TypeCasting {
public static void main(String[] args) {
// TODO Auto-generated method stub
int i = 100;
// Byte > Short > Int > Long > Float > Double conversions are OK
//automatic type conversion
long l = i;
//automatic type conversion
float f = l;
System.out.println("Int value "+i);
System.out.println("Long value "+l);
System.out.println("Float value "+f);
// Double > Float > Long > Int > Short > Byte conversions require type casting
double d = 100.94;
// without type casting
//long lngValue = d; // - results in an error! Type Mismatch!
// with explicit type casting
long lng = (long)d;
//explicit type casting
int integer = (int)lng;
System.out.println("Double value "+d);
//fractional part lost
System.out.println("Long value "+lng);
//fractional part lost
System.out.println("Int value "+integer);
}
}