java当中throws子句在继承当中overrride时有什么规则?

JAVA学习网 2018-09-25 15:47:02

8.throws子句在继承当中overrride时的规则  (视频下载) (全部书籍) 马克-to-win:当子类方法override父类方法时,throws子句不能引进新的checked异常。换句话说:子类override方法的throws子句checked异常不能比父类多。马克-to-win:上面一条是死语法规定,这种规定,实际上都是源于checked异常这种最初的设计。

例:1.8.1-本章源码

import java.io.IOException;
class Animal{
    void call() throws IOException
    {
        System.out.println("Animal");
    }
}
class Dog extends Animal{
    void call() throws IOException
    {
        System.out.println("Dog");
    }
}

public class Test {

。。。。。。。。。。。。。。。。。
详情请进:http://www.mark-to-win.com/index.html?content=JavaBeginner/javaUrl.html&chapter=JavaBeginner/JavaBeginner5_web.html#throwsInInheritanceOverride

阅读(2315) 评论(0)