在Java中进行基本类型的类型转换

short a = 1;

short b = 2;

那么 a+b 是什么类型?

 

答案:int型;

   a,b相加前先自动转换成了int,相加后当然是int。在编译器能看到Type mismatch: cannot convert from int to short

posted @ 2019-02-08 16:37  猫不会游泳却爱吃鱼  阅读(106)  评论(0)    收藏  举报