[求助]一个简单的类型转换问题
public class Test{
public static void main(String[] args)
{
byte b=127;
byte c=126;
byte d=(byte)(b*c);
System.out.println(d); //为什么输出-126, 按我的想法上一步相乘应该会超出byte的范围,为什么没有报错呀?
}
}
大家帮我解决一下这个疑问..谢谢!
再添一个问题
which is true?
A. Any statement that may throw an Exception must be enclosed in a try block.
//Standard Exception (Runtime Exception) is not
B. Any statement that may throw an Error must be enclosed in a try block.
C. Any statement that may throw an RuntimeException must be enclosed in a try block.
D.No exception are subclass of Error.
答案写的是D...但Error类也有子类呀....如AnnotationFormatError, AssertionError, AWTError, CoderMalfunctionError, FactoryConfigurationError, FactoryConfigurationError, IOError, LinkageError, ServiceConfigurationError, ThreadDeath, TransformerFactoryConfigurationError, VirtualMachineError
应该选什么呢?
我多问个问题
public class Test
{
public static void main(String[] args)
{
int b=99999999;
int c=99999999;
int d = b*c; //b*c = 9999999900000001 这个数远远超出了int的最大值,为什么也不会报错呀?
System.out.println(d);
System.out.println(Integer.MAX_VALUE); //2147483647
}
}
[此贴子已经被作者于2007-4-30 23:46:23编辑过]