java基础:表达式的自动类型转换
1.表达式的自动类型转换:
(1)在表达式中,小范围的变量,会自动转换为表达式中较大范围的类型,再参与运算


代码:
package com.itheima.type; public class Type1 { public static void main(String[] args) { byte a=10; int b=20; long c=30; long rs=a+b+c; System.out.println(rs); double re2=a+b+1.0; System.out.println(re2); byte i=10; short j=30; int rs3=i+j; System.out.println(rs3); //面试笔试题 byte b1=10; byte b2=80; int b3=b1+b2;//在表达式中byte,short,char是直接转换成int参与运算的 } }
总结:

浙公网安备 33010602011771号