【311天】我爱刷题系列070(2017.12.13)

叨叨两句

  1. 继续~
  2. 贫穷不可怕,可怕的是由于贫穷,而缺失长期目标、不作长远规划、不与人合做、不追求双赢、自我打击、对世界充满敌意

牛客网——java专项练习049

1

Which lines of the following will produce an error?java

1. byte a1 = 2, a2 = 4, a3;
2. short s = 16;
3. a2 = s;
4. a3 = a1 * a2;

正确答案: A 你的答案: C (错误)
A Line 3 and Line 4
B Line 1 only
C Line 3 only
D Line 4 onlycode

数值型变量在默认状况下为Int型,byte和short型在计算时会自动转换为int型计算,结果也是int 型。因此a1*a2的结果是int 型的
byte+byte=int,低级向高级是隐式类型转换,高级向低级必须强制类型转换,byte=char=short<int<long<float<double

byte,short,char是同级别的,不能自动转换,须要增强转