举例:
class Test1
{
public static void main(String[] args)
{
byte b = 1;
short s = 2;
char c = 'c';
int i = 3;
long l = 4;
float f = 5.0f;
double d = 6.0;
s = b;//byte类型自动转换为short类型
System.out.println("变量b的值为: " + b);
i = c;//char类型自动转换为int类型
System.out.println("变量i的值为:" + i);
i = s;//short类型自动转换为int类型
System.out.println("变量i的值为:" + i);
l = i;//int类型自动转换为long类型
System.out.println("变量l的值为:" + l);
f = l;//long类型自动转换为float类型
System.out.println("变量f的值为:" + f);
d = f;//float类型自动转换为double类型
System.out.println("变量d的值为:" + d);
d = b;//byte类型自动转换为double类型
System.out.println("变量d的值为:" + d);
d = f + d;//加法运算,f先自动转换为double类型
System.out.println("变量d的值为:" + d);