import java.io.IOException; public class ExceptionTest( public static void main (String[]args) try ( methodA(); ) catch (IOException e) ( system.out.printIn(“Caught IOException”); ) catch (Exception e) ( system.out.printIn(“Caught Exception”); ) ) public void methodA () { throw new IOException (); } What is the result?()
A: The code will not compile.
B: The output is caught exception.
C: The output is caught IOException.
D: The program executes normally without printing a message.
A: The code will not compile.
B: The output is caught exception.
C: The output is caught IOException.
D: The program executes normally without printing a message.
举一反三
- 请说出下列程序的输出结果_____________,_____________。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();}}
- 给出下列程序的输出结果。import java.io.IOException;public class E {public static void main(String args[]){int m =10;try {methodA();m = 100;}catch(IOException e){m = 1000;}System.out.println(m);}public static void methodA() throws IOException{throw new IOException();}}
- 阅读下面的代码段,屏幕的输出是什么?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”
- 当编译并且运行下面程序时会出现什么结果? public class ThrowsDemo{ static void throwMethod() { System.out.print("Inside throwMethod"); throw new IOException("demo"); } public static void main(String [] args){ try{ throwMethod(); }catch(IOException e){ System.out.println("Cauht"+e); } } }
- 以下程序的执行结果是?()public static void main(String[] args) {// TODO 自动生成的方法存根try{methodA();}catch(IOException e){System.out.print("你好");}finally{System.out.print(" fine thanks.");}System.out.print(" end");}public static void methodA()throws IOException{System.out.print(" ok ");throw new IOException();}} A: ok 你好 fine thanks. end B: 你好 fine thanks. end C: ok 你好 end D: ok 你好 fine thanks.