关于基本类型的问题!!急
请高手先看看下边的这个程序!
public class ByteAndInt{
public static void main(String[] args){
byte a=126;
byte b=127;
byte c;
c=a+b;
System.out.println(c);
}
}
这个程序不能通过编译!输出结果是:
--------------------Configuration: SCJP - j2sdk1.4.0 <Default>--------------------
D:\MaoJava\SCJP\ByteAndInt.java:10: possible loss of precision
found : int
required: byte
c=a+b;
^
1 error
小弟想不能通过编译的原因是:byte类型+byte类型的都自动转换成int类型的!但小弟试着编译下边的程序:
public class ByteAndInt{
public static void main(String[] args){
int a=2147483647;//2的31次方-1
int b=2147483646;//2的31次方-2
int c;
c=a+b;
System.out.println(c);
}
}
这个程序能够通过编译。这可就使小弟迷惑了!为什么同样的道理这个却可以通过!!
请高手指点一二!
小弟先谢了!