写出下列程序的运行结果

class Cat {
    void mi() throws NullPointerException {
        System.out.println("Cat mi mi ..");
    }
}

class SmallCat extends Cat {
    int i = 8;

    void mi() throws Exception {
        System.out.println("SmallCat mi mi ..");
    }

    public static void main(String[] a) throws Exception {
        Cat cat = new SmallCat();
        cat.mi();
    }
}

参考解答

编译错误

子类SmallCat的mi()方法覆盖了父类Cat中的mi()方法,子类方法不能抛出比父类方法范围更大的异常,所以编译会发生错误


results matching ""

    No results matching ""