类型转化
由于Java是强类型语言,所有要进行有些运算的时候的,需要用到类型转换。
低------------高
byte short char->int->long->float->double
public class demo01 {
public static void main(String[] args) {
int i=128;
byte b=(byte)i; //内存溢出
//强行类型转换 (类型)变量名
System.out.println(i);
System.out.println(b);
int a=127;
double c=a;
System.out.println(a);
System.out.println(c);
//自动转换 低---高
}
/*
1. 不能对布尔值进行转换
2. 不能把对象类型转换为不相干的类型
3. 在把高容量转换到底容量的时候,强制转换
4. 转换的时候可能存在内存溢出,或者精度问题!
*/
}
2020/12/29