因此,如果我这样做-
class A{
{
throw new FileNotFoundException();
}
public A() throws IOException{
// TODO Auto-generated constructor stub
}
}
这会导致编译时出现错误“初始化程序必须正常完成”。
同时
class A{
{
File f=new File("a");
FileOutputStream fo=new FileOutputStream(f);
fo.write(3);
}
public A() throws IOException{
// TODO Auto-generated constructor stub
}
}
这段代码没有显示任何编译时错误。为什么即使我在构造函数中声明了throws子句,先前的代码还是无法编译?