1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
class
A
extends
Exception{
A(){
super
();
}
A(String msg){
super
(msg);
}
}
class
B
extends
A{
B(){
super
();
}
B(String msg){
super
(msg);
}
}
public
class
Test{
public
static
void
main(String[] args){
try
{
throw
new
B();
}
catch
(A e){
System.out.println(
"A"
);
}
catch
(B e){
//编译挂了知道不?异常中发生多态时一定要注意要将父类的异常写在下边!
System.out.println(
"B"
);
}
catch
(Exception e){
System.out.println(
"Exception"
);
}
}
}
|
本文转自 小眼儿 博客园博客,原文链接:http://www.cnblogs.com/hujunzheng/p/3872738.html,如需转载请自行联系原作者