首页 > 其他 > 详细

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

时间:2021-03-15 11:16:29      阅读:23      评论:0      收藏:0      [点我收藏+]

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 {
    public static void main(String args[]) throws IOException {
        Dog d = new Dog();
        d.call();
    }
}

 

更多内容请见原文,文章转载自:https://blog.csdn.net/qq_44639795/article/details/103108565

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

原文:https://www.cnblogs.com/shituxingzhe1949/p/14535405.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!