Java 异常处理(2) : 方法重写的规则之一:
1 package com.bytezero.throwable; 2 3 import java.io.FileNotFoundException; 4 import java.io.IOException; 5 6 /** 7 * 8 * @Description 方法重写的规则之一: 9 * @author Bytezero·zhenglei! Email:420498246@qq.com 10 * @version 11 * @date 下午2:50:20 12 * @ 子类重写的方法抛出的异常类型不大于父类被重写的方法抛出的异常类型 13 * 14 * 15 */ 16 public class OverrideTest { 17 18 public static void main(String[] args) { 19 OverrideTest test = new OverrideTest(); 20 test.display(new SubClass()); 21 } 22 23 public void display(SuperClass s) { 24 try { 25 s.method(); 26 } catch (IOException e) { 27 // TODO Auto-generated catch block 28 e.printStackTrace(); 29 } 30 } 31 } 32 33 class SuperClass{ 34 35 public void method() throws IOException{ 36 37 } 38 } 39 40 class SubClass extends SuperClass{ 41 public void method()throws FileNotFoundException { 42 43 } 44 45 }
本文来自博客园,作者:Bytezero!,转载请注明原文链接:https://www.cnblogs.com/Bytezero/p/15385904.html