javase学习之自动类型转换和转换原理内存图解

1.基本类型------自动转换规则如下:

    byte,short,char--->int------->long------>float------>double

(byte,short,char参与运算,首先无条件转成 int 类型,再继续参与运算)

举几个例子:

         //1.  short相加提升为int

                  short s1 = 10;

                   short s2 = 20;

                   int c = s1 + s2;

       //2.    byte   +    short   提升为   int

                   byte b1 = 10;

                   short s3 = 30;

                   int d = b1+s3;

      //3.     int    +   double   提升    double

                   int i = 10;

                   double d = 30.0;

                   double e = i+d;//int +  double

2.转换原理内存图解:

javase学习之自动类型转换和转换原理内存图解