Java-方法重写中的声明异常(throws)原则

2019-07-31 14:40:19 浏览数 (1)

版权声明: https://blog.csdn.net/li_xunhuan/article/details/89041674

代码语言:javascript复制
package cn.lixunhuan.oo1;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.ParseException;

public class TestRangofExrends {
}

class A {
public void method() throws IOException {
}
}

class B extends A {
public void method() throws FileNotFoundException {
}
}

class C extends A {
public void method()
}

class D extends A {
public void method() throws Exception {
}
}

class E extends A {
public void method() throws IOException, FileNotFoundException {
}
}

class F extends A {
public void method() throws IOException, ParseException {
}
}

编译结果是: DF报错,其余合法; 先给出异常继承关系:

方法重写中的声明异常原则:

0 人点赞