import java.io.IOException;   public class ExceptionTest(   public static void main (Stringargs)  try (   methodA();   ) catch (IOException e) (   system.out.printIn(“Caught IOException”);  ) catch (Exception e) (   system.out.printIn(“Caught Exception”);

题目

import java.io.IOException;   public class ExceptionTest(   public static void main (Stringargs)  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.
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

importjava.io.IOException;publicclassExceptionTest(publicstaticvoidmain(String[]args)try(methodA();)catch(IOExceptione)(system.out.printIn(CaughtIOException”);)catch(Exceptione)(system.out.printIn(CaughtException”);))publicvoidmethodA(){thrownewIOException();}Whatistheresult?()

A.Thecodewillnotcompile.

B.Theoutputiscaughtexception.

C.TheoutputiscaughtIOException.

D.Theprogramexecutesnormallywithoutprintingamessage.


参考答案:A

第2题:

下面程序输出的结果是什么? ( ) public class Quiz2 { public static void main(String args[]) { try {throw new MyException(); }catch(Exception e) { System.out.println("It's caught!"); }finally{ System.out.println("It's finally caught!"); } } } class MyException extends Exception{}

A.It's finally caught!

B.It's caught!

C.It's caught!/It's finally caught!

D.无输出


正确答案:C
解析:本题是对异常处理基本知识的考查。本程序中创建了一个异常类MyException,它的祖先类是Exception。在程序中,程序先发出异常MyException,下面是catch捕获异常,但是catch列表中并没有与之对应的MyExcepfion,但是有一个Exception,它是MyException的祖先类。如果有多种异常需要捕获,在安排catch语句的顺序时要注意,应该首先捕获最特殊的类,然后逐渐一般化。例如,IOExcepfion类是FileNotFoundException类的父类;就应该首先捕获FileNotFoundException异常,然后捕获IOExcepfion异常。所以运行结果是It'scaught!/It'sfinallycaught!

第3题:

下列程序的运行结果是

public class test{

private String[] data={“10”,“10.5”};

public void fun(){

double s=0;

for(int i=0;i<3;i++){

try{

s=s+Integer .parseInt(data[i]);

}catch(Exception e){

System.out.print(“errorl:”+data[i]);

}

}

}

public static void main(String[]args){

try{

testd=new test();

d .fun();

}catch(Exception e){

System.out.printIn(“error2”);

}

}

}

A.errorl:10.5

B.error2

C.errorl:10.5 error2

D.以上都不对


正确答案:B

第4题:

public class Test {  public static void aMethod() throws Exception {  try {  throw new Exception(); } finally {  System.out.println(“finally”);  }  }  public static void main(String args[]) {  try {  aMethod();  } catch (Exception e) {  System.out.println(“exception”);  }  System.out.println(“finished”);  }  }  What is the result?()  

  • A、 finally
  • B、 exception finished
  • C、 finally exception finished
  • D、 Compilation fails.

正确答案:C

第5题:

public class foo {   public static void main (stringargs)   try {return;}   finally {system.out.printIn(“Finally”);}   }     What is the result?()  

  • A、 The program runs and prints nothing.
  • B、 The program runs and prints “Finally”
  • C、 The code compiles, but an exception is thrown at runtime.
  • D、 The code will not compile because the catch block is missing.

正确答案:B

第6题:

importjava.io.IOException;publicclassExceptionTest(publicstaticvoidmain(Stringargs)try(methodA();)catch(IOExceptione)(system.out.printIn(CaughtIOException”);)catch(Exceptione)(system.out.printIn(CaughtException”);))publicvoidmethodA(){thrownewIOException();}Whatistheresult?()

A.Thecodewillnotcompile.

B.Theoutputiscaughtexception.

C.TheoutputiscaughtIOException.

D.Theprogramexecutesnormallywithoutprintingamessage.


参考答案:A

第7题:

请阅读下列程序代码,然后将程序的执行结果补充完整。横线处应填写的内容是( )。 程序代码: public class throwsExeeption{ static void Proc(intsel) throws Arithmetic Exception,Array Index Out Of Bounds Exception{ System.out.println("InSituation"+sel); if(sel= =0){ System.OUt.println("noException caught"); return; } else if(sel= =l){ int iArray[]=newint[4]; iArray[1]=3; } } public static void main(String args[]){ try{ Proe(O); Proc(1); } catch(Array Index Out Of Bounds Exception e){ System.out.println("Catch"+e); } finally{ System.out.println("inProcfinally"): } } } 执行结果: In Situation 0 no Exception caught in Proc finally

A.In Situation l

B.In Situation

C.with Catch

D.int iArray l


正确答案:A
A。【解析】本题考查考生阅读Java程序的能力。题目程序看似复杂,但流程非常简单。程序的public类是thtowsExeeption,类中定义了Proe(intsel)方法。程序入口是main方法,使用try-catch-finally来捕获ArithmeticExeeption和ArrayIndexOutOfBoundsExeeption异常,这两个异常是关于算术异常或数组索引越界的异常。执行Proe(0)时,输出InSituation0和noExceptioncaught两条信息;执行Proc(1)时,输出InSituationl和inProcfinally两条信息。整个程序并未发生异常。

第8题:

( 21 )请阅读下面程序

import java.io. *;

public class ExceptionCatch{

public static void main ( String args[] ){

try {

FileInputStream fis=new FilelnputStream ( "text" ) ;

System.out.pfntln ( "content of text is : ” ):

} catch ( FileNotFoundException e ){

System.out.println ( e ) ;

System.out.println ( "message:"+e.getMessageQ ) ;

e.printStackTrace ( System.out ) ;

}____________;

System.out.println ( e ) ;

}

}

为保证程序正确运行,程序中下划线处的语句应是

A ) catch ( Fiie put eam s )

B ) e printStackTrace ()

C) catch ( IOException e )

D) System.out.printin ( e )


正确答案:C

第9题:

public class foo {  public static void main (string[]args)  try {return;}  finally {system.out.printIn(“Finally”);}  }  What is the result?()

  • A、 The program runs and prints nothing.
  • B、 The program runs and prints “Finally”
  • C、 The code compiles, but an exception is thrown at runtime.
  • D、 The code will not compile because the catch block is missing.

正确答案:B

第10题:

public class ExceptionTest {   class TestException extends Exception {}   public void runTest () throws TestException {}   public void test () /* Point X*/ {   runTest ();   }   }   At point X on line 4, which code can be added to make the code compile?()  

  • A、 Throws Exception.
  • B、 Catch (Exception e).
  • C、 Throws RuntimeException.
  • D、 Catch (TestException e).
  • E、 No code is necessary.

正确答案:B

更多相关问题