Which lines of the following will produce an error?
1. byte a1 = 2,a2 = 4, a3;
2. short s = 16;
3. a2 = s;
4. a3 = a1 * a2;
A Line 3 and Line4
B Line 1 only
C Line 3 only
D Line 4 only
考点:考察求职者对类型转换的掌握
出现频率:★★★★★
【面试题分析】
1、Java中整数默认 类型为int型,浮点默认为double型;
2、对于byte型运算时,会自动转化为int 型;
3、对于byte\short\char同级别运算时,需要强制转换;
4、高级型向低级需要强制类型转换;
高级向低级必须强制类型转换byte<char<short<int<long<float<double
short,byte,char是同级别的,所有逻辑操作都会自动转换成int型再进行相关运算
所以参考答案是(A)