class Sup{
public static String get(Integer i){
return "Sup";
}
}
class Sub extends Sup{
public static String get(Integer i) throws IOException{
return "Sub";
}
}
上面的程序给出了编译错误Exception IOException is not compatible with throws clause in Sup.get(Integer)
这两种方法都是静态的,所以不是覆盖的情况。那么为什么这个错误?
如果我将Override annotation添加到子类中,只是要清楚表明它不是覆盖的情况:
@Override
public static String get(Integer i){
return "Sub";
}
它给出了编译错误The method get(Integer) of type Sub must override or implement a supertype method
。
静态的子类方法中异常缺少什么?