在我准备复试的一篇论文中,有人问我“catch blocks 可以是多态的吗?”。
catch
如果为真,那么将多个块称为多态对我来说没有意义。如果catch
块无法命名并且仅在其方法头中包含参数,是否是多态性?
例如:
try {
//...
} catch (FileNotFoundException e) {
System.err.println("FileNotFoundException: " + e.getMessage());
throw new SampleException(e);
} catch (IOException e) {
System.err.println("Caught IOException: " + e.getMessage());
}
在此,这两个catch
块是多态的吗?