异常限制

11.10

子类抛出受控异常的限制:

代码部分:

import java.io.*;


public class OverrideThrows
{
public void test()throws IOException
{
FileInputStream fis = new FileInputStream("a.txt");
}
}
class Sub extends OverrideThrows
{
//如果test方法声明抛出了比父类方法更大的异常,比如Exception
//则代码将无法编译……
public void test() throws FileNotFoundException
{
//...
}
}

posted @ 2020-11-10 21:53  潘福龙  阅读(53)  评论(0编辑  收藏  举报