在千峰第27天
“学如逆水行舟”
中国加油,武汉加油,千峰加油,我自己加油。
5、
class MyException1 extends Exception {
public MyException1() {
super();
}
public MyException1(String message) {
super(message);
}
}
class MyException2 extends RuntimeException {
public MyException2() {
super();
}
public MyException2(String message) {
super(message);
}
}
6、
public class TestMyException {
public static void main(String args[]) {
int n;
// 读入n
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
try {
m(n);
} catch (MyException1 ex1) {
// 输出ex1详细的方法调用栈信息
ex1.printStackTrace();
} catch (MyException2 ex2) {
// 输出ex2的详细信息
System.out.println(ex2.getMessage());
// 并把ex2重新抛出
throw ex2;
}
}
public static void m(int n) throws MyException1 { // 声明抛出MyException1
if (n == 1) {
// 抛出MyException1
// 并设定其详细信息为“n == 1”
throw new MyException1("n == 1");
} else {
// 抛出MyException2
// 并设定其详细信息为“n == 2”
throw new MyException2("n == 2");
}
}
}
8、
1:AB
2:D
10、
①100
②100
12、
不能
应该修改为
import java.io.*;
class MySuper {
public void m() throws IOException {
}
}
class MySub extends MySuper {
public void m() throws EOFException {
}
}
class MySub2 extends MySuper {
public void m() throws FileNotFoundException {
}
}