阅读下面的代码段,屏幕的输出是什么?public static void main(String[] args) { try{tryThis();return;}catch(IOException x1){ System.out.println("exception 1");return;}catch(Exception x2){System.out.println("exception 2");return;}finally{ System.out.println("finally");} } static void tryThis() throws IOException{ throw new IOException(); }
A: ”exception1”后面跟着”finally”
B: ” exception2”后面跟着“finally”
C: ”exception1”
D: ”exception2”
A: ”exception1”后面跟着”finally”
B: ” exception2”后面跟着“finally”
C: ”exception1”
D: ”exception2”
举一反三
- 读程序,写出和程序输出格式一致的输出结果。 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); } }
- (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 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
- 请说出下列程序的输出结果_____________,_____________。import java.io.IOException;public class E {public static void main(String args[]){try { methodA();}catch(IOException e){System.out.print("你好");return;}finally {System.out.println("thanks");}}public static void methodA() throws IOException{throw new IOException();}}
- class Demo{ public static void main(String[] args){ int x = 0; try{ x = div(1,2); }catch(Exception e){ System.out.println(e); } System.out.println(x) ; } public static int div(int a,int b){ return a / b ; } }