1.不同类型数据间的优先关系如下:
低------------------------------------------->高
byte,short,char-> int -> long -> float -> double
2.自动类型转换规则
整型,实型,字符型数据可以混合运算。运算中,不同类型的数据先转化为同一类型,然后进行运算,转换从低级到高级;
操作数1类型
|
操作数2类型
|
转换后的类型
|
byte、short、char |
int |
int |
byte、short、char、int |
long |
long |
byte、short、char、int、long |
float |
float |
byte、short、char、int、long、float |
double |
double |
3.强制类型转换
高级数据要转换成低级数据,需用到强制类型转换,如:
int i;
byte b=(byte)i; /*把int型变量i强制转换为byte型*/
|