//typeconversion.java
//Java中的类型转换
public class typeconversion
{
public static void main(String[] args)
{
char a=1;
byte b=2;
short c=3;
int d=4;
byte e;
e=(byte)(a+b+c+d); //将"a+b+c+d"的值强制转化为byte型
short f;
f=(short)(a+b+c+d); //将"a+b+c+d"的值强制转化为short型
int g;
g=a+b+c+d; //a,b,c,d 自动转换为int型再计算
float h;
h=a+b+c+d; //a,b,c,d 自动转换为float型再计算
double i;
i=a+b+c+d; //a,b,c,d 自动转换为double型再计算
System.out.println("e="+e);
System.out.println("f="+f);
System.out.println("g="+g);
System.out.println("h="+h);
System.out.println("i="+i);
}
}
该段中的这句 e=(byte)(a+b+c+d); 前面char a=1; 那a就是字符型数据,能和b,c,d整型的数相加? 先自动转换一次再相加,再4者之和转化为byte 型?