Subclass throw checked exceptions restrictions

package we;

import java.io. *;

public class OverrideThrows
{
    public void test()throws IOException
    {
        FileInputStream fis = new FileInputStream("a.txt");
    }
}
class Sub extends OverrideThrows
{
    // If the test method declaration throws greater than the parent class method exceptions, such as Exception
    // then the code will not compile ......
    public void test() throws FileNotFoundException
    {
            //...
    }
} 
A throws clause subclass thrown exception, is not the same name as its base class method throws exception parent class object.

Guess you like

Origin www.cnblogs.com/yyl141/p/11789348.html