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");
	   }
   }
}

  

相关文章:

  • 2022-12-23
  • 2022-01-16
  • 2022-01-06
  • 2021-08-12
  • 2022-01-07
  • 2022-12-23
  • 2021-11-09
  • 2021-07-05
猜你喜欢
  • 2021-06-07
  • 2021-08-10
  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
  • 2021-07-19
相关资源
相似解决方案