下面程序的执行结果是( )。public class Test {public static void main(String[] args) {new Test().test();}public void test(){try{System.out.print("try");}catch(ArrayIndexOutOfBoundsException e){System.out.print("catch1");}catch(Exception e){System.out.print("catch2");}finally{System.out.println("finally");}}}
A: try finally
B: try catch1 finally
C: try catch2 finally
D: finally
A: try finally
B: try catch1 finally
C: try catch2 finally
D: finally
举一反三
- (9-3)请阅读程序,然后写出程序运行结果。(请注意输出不换行) public class Demo3 { public static void main(String[] args) { int a=9,b=0; double x=9,y=0; try { int c=a/b; }catch(Exception e1) { System.out.print("1"); try { double z=x/y; }catch(Exception e2) { System.out.print("2"); }finally { System.out.print("3"); } }finally { System.out.println("4"); } } }
- public void test() { try { oneMethod(); Console.WriteLine("condition 1"); } catch (ArrayIndexOutOfBoundsException e) { Console.WriteLine ("condition 2"); } catch(Exception e) { Console.WriteLine ("condition 3"); } finally { Console.WriteLine ("finally"); } } 在oneMethod()方法运行正常的情况下将显示( )( 3 分)
- 读程序,写出和程序输出格式一致的输出结果。 public class J_Test { public static void mb_method(int i) { try { if(i == 1) throw new Exception(); System.out.print("1"); } catch(Exception ex) { System.out.print("2"); return; } finally { System.out.print("3"); } System.out.print("4"); } public static void main(String[] args) { mb_method(0); mb_method(1); } }
- 以下的try~catch语句,哪种是不正确的? A: try{}catch(){}finally{} B: try{}catch(){}catch(){}finally{} C: try{}catch(){} D: try{}finally{}
- 以下程序有什么错误?public class Test {public static void main (String[] args) {try {System.out.println("Welcome to Java");}}} A: 没有catch块就不能有try块 B: 没有catch块或finally块就不能有try块 C: 未声明异常的方法调用,不能放在try块内 D: 没有错误