给出下列程序的输出结果。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();}}
举一反三
- 请说出下列程序的输出结果_____________,_____________。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 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.
- 当编译并且运行下面程序时会出现什么结果? 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.
- 读下面代码,哪个选项是正确的( )import java.io.*;public class Test2{public static void main(String []args)throws IOException{if(args[0]==”hello”)throw new IOException();}} A: 没有错误,程序编译正确 B: 编译错误,不能够在main方法中抛出异常 C: 编译错误,IOException是一个系统异常,不能够由application程序产生 D: 没有输出结果