JAVA基础复习:第二句出错b=b1+b2;,第三句b3=b1+2;都是错误的。 b是byte数据类型,3和4是int数据类型,
b1和b2在运算时会自动转换为int类型,而int类型的数据赋值给byte类型时就会有可能数据溢出,所以错误。
b3+2时也同理。
3+4的结果是常量,所以可以赋值给b。
JAVA基础复习:第二句出错b=b1+b2;,第三句b3=b1+2;都是错误的。 b是byte数据类型,3和4是int数据类型,
b1和b2在运算时会自动转换为int类型,而int类型的数据赋值给byte类型时就会有可能数据溢出,所以错误。
b3+2时也同理。
3+4的结果是常量,所以可以赋值给b。