我正在为 Java 助理考试而学习,并且在考试条件下正在努力确定哪些是已检查的,哪些是未检查的。我知道如果我可以根据我在这里阅读的内容编写代码,我可以查找它或执行 instanceof - 但是有没有一种简单的方法可以确定它。我捡了一些,但发现很难记住它们。下面是一个依赖于这些知识的问题的考试。
public static String readData (Path filePath)
throws IOException, IllegalArgumentException {
//implementation omitted
}
哪两个代码片段会编译?
public static void main(String[] args) {
try {
readData(Paths.get("test"));
} catch (IllegalArgumentException ex) {
System.err.println(ex);
}
}
public static void main(String[] args)
throws IOException{
readData(Paths.get("test.txt"));
}
public static void main(String[] args)
throws IllegalArgumentException{
readData(Paths.get("test.txt"));
}
public static void main(String[] args) {
readData(Paths.get("test.txt"));
}
public static void main(String[] args) {
try {
readData(Paths.get("test"));
} catch (IOException ex) {
System.err.println(ex);
}
}