try {  int x = 0;  int y = 5 / x;  } catch (Exception e) {  System.out.println(“Exception”);  } catch (ArithmeticException ae) {  System.out.println(“Arithmetic Exception”);  }  System.out.println(“finished”);  What is the result?()  A、 finishedB、 Except

题目

try {  int x = 0;  int y = 5 / x;  } catch (Exception e) {  System.out.println(“Exception”);  } catch (ArithmeticException ae) {  System.out.println(“Arithmetic Exception”);  }  System.out.println(“finished”);  What is the result?()  

  • A、 finished
  • B、 Exception
  • C、 Compilation fails.
  • D、 Arithmetic Exception

相似考题
参考答案和解析
正确答案:D
更多“try {  int x = 0;  int y = 5 / x;  } catch (Exception e) {  System.out.println(“Exception”);  } catch (ArithmeticException ae) {  System.out.println(“Arithmetic Exception”);  }  System.out.println(“finished”);  What is the result?()  A、 finishedB、 Excepti”相关问题
  • 第1题:

    try{intx=0;inty=5/x;}catch(Exceptione){System.out.println(Exception”);}catch(ArithmeticExceptionae){System.out.println(ArithmeticException”);}System.out.println(finished”);Whatistheresult?()

    A.finished

    B.Exception

    C.Compilationfails.

    D.ArithmeticException


    参考答案:D
    ThecorrectanswertothisquestionisD.Whenanintvalueisdividedbyzero,aruntimeexceptionoccurs.Therearenocompilationerrors.

  • 第2题:

    下面程序的输出结果是 public class Test{ public static void main(String[] args){ int[]array={2,4,6,8,10}; int size=6; int result=-1: try{ for(int i=0;i<size&&result==-1;i++) if(array[i]==20)result=i; }catch(ArithmeticException e){ System.out.println("Catch---1"); }catch(ArrayIndexOutOfBoundsException e){ System.out.println("Catch---2"); }catch(Exception e){ System.out.println("Catch---3"); } } }

    A.Catch---1

    B.Catch一--2

    C.Catch---3

    D.以下都不对


    正确答案:B
    解析:ArithmeticException是当出现异常的运算条件时,抛出此异常。例如,一个整数“除以零”时,是抛出此类的一个实例;ArrayIndexOutOfBoundsException是用非法索引访问数组时抛出的异常。如果索引为负或大于等于数组大小,则该索引为非法索引。本程序中,数组大小为5个元素,数组下标为0~4,而循环为0~5,数组越界,所以会捕获ArrayIndexOutOfBoundsException。

  • 第3题:

    阅读下列程序片段。 Public void test{ Try{ sayHello; system.out.println("hello"): }catch(ArraylndexOutOfBoundException e){ System.out.println("ArraylndexOutOfBoundExcep— tion"); }catch(Exception e){ System.out.println("Exception"): }finally{ System.Out.println("finally"); } } 如果sayHello方法正常运行,则test方法的运行结果将是( )。

    A.Hello

    B.ArraylndexOutOfBondsException

    C.Exception Finally

    D.Hello Finally


    正确答案:D
    D。【解析】sayHello方法正常运行则程序不抛出异常,并执行finally,所以为D。

  • 第4题:

    下列程序的输出结果是( )。 Public class Test{ Public static void main(String[]args){ int[]array=(2,4,6,8,10); int size=6; int result=-l: try{ for(int i=0;i<sizeresult= =-1:) if(array[i]= =20)result=i: } catch(ArithmeticException e){ System.out.println("Catch---1"); } catch(ArraylndexOutOfBoundsException e){ System.out.println("Catch---2"): } catch(Exception e){ System.out.println("Catch---3"): } }

    A.Catch---1

    B.Catch---2

    C.Catch---3

    D.以上都不对


    正确答案:B
    B。【解析】本题考查了数组及for循环。本题数组定义的值为5,下标从0~4。数组越界,所以答案为B。

  • 第5题:

    ( 17 )下列程序的输出结果是

    public class Test{

    public static void main(String[] args){

    int [] array={2,4,6,8,10};

    int size=6;

    int result=-1;

    try{

    for{int i=0;i<size && result==-1;i++}

    if(array[i]==20) result=i;

    }

    catch(ArithmeticException e){

    System.out.println( " Catch---1 " );

    catch(ArrayIndexOutOfBoundsException e){

    System.out.println( " Catch---2 " );

    catch(Exception e){

    System.out.println( " Catch---3 " );

    }

    }

    A ) Catch---1

    B ) Catch---2

    C ) Catch---3

    D )以上都不对


    正确答案:U

    答案暂缺

  • 第6题:

    现有:  class Parser extends Utils  { public static void main (String[]  args)    {     try{System.out.print (new Parser().getlnt("42"));      } catch (Exception e)    {      System.out.println("Exc");  }      }  int getlnt (String arg) throws Exception  {      return Integer.parselnt (arg);      }       class Utils  {  int getlnt (String arg)    {return 42;  }      }      结果为()    

    • A、 42
    • B、 Exc
    • C、 42Exc
    • D、编译失败

    正确答案:D

  • 第7题:

    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

  • 第8题:

    try {  if ((new Object))(.equals((new Object()))) {  System.out.println(“equal”);  }else{  System.out.println(“not equal”);  }  }catch (Exception e) {  System.out.println(“exception”);  }   What is the result? () 

    • A、 equal
    • B、 not equal
    • C、 exception
    • D、 Compilation fails.

    正确答案:D

  • 第9题:

    1. class Exc0 extends Exception { }  2. class Exc1 extends Exc0 { }  3. public class Test {  4. public static void main(String args[]) {  5. try {  6. throw new Exc1();  7. } catch (Exc0 e0) {  8. System.out.println(“Ex0 caught”);  9. } catch (Exception e) {  10. System.out.println(“exception caught”);  11. }  12. }  13. }  What is the result?()  

    • A、 Ex0 caught
    • B、 exception caught
    • C、 Compilation fails because of an error at line 2.
    • D、 Compilation fails because of an error at line 6.

    正确答案:A

  • 第10题:

    单选题
    try {  int x = 0;  int y = 5 / x;  } catch (Exception e) {  System.out.println(“Exception”);  } catch (ArithmeticException ae) {  System.out.println(“Arithmetic Exception”);  }  System.out.println(“finished”);  What is the result?()
    A

     finished

    B

     Exception

    C

     Compilation fails.

    D

     Arithmetic Exception


    正确答案: A
    解析: The correct answer to this question is D. When an int value is divided by zero, a runtime exception occurs. There are no compilation errors. 

  • 第11题:

    单选题
    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
    解析: 暂无解析

  • 第12题:

    单选题
    public class Test {  public static void main(String[] args) {  int x = 0;  assert (x > 0): “assertion failed”;  System.out.println(“finished”);  }  }  What is the result?()
    A

     finished

    B

     Compilation fails.

    C

     An AssertionError is thrown.

    D

     An AssertionError is thrown and finished is output.


    正确答案: D
    解析: This question is a bit tricky because it lacks the following information: It should include a statement that says whether or not assertions are enabled. If they are indeed enabled, the 
    correction answer is C. but if they are not, the correct answer is A. Assertions are not enabled by default so if the question is not changed, the most logical answer is A.

  • 第13题:

    publicclassTest{publicstaticvoidaMethod()throwsException{try{thrownewException();}finally{System.out.println(finally”);}}publicstaticvoidmain(Stringargs[]){try{aMethod();}catch(Exceptione){System.out.println(exception”);}System.out.println(finished”);}}Whatistheresult?()

    A.finally

    B.exceptionfinished

    C.finallyexceptionfinished

    D.Compilationfails.


    参考答案:C

  • 第14题:

    下列代码的执行结果是( )。 public class Test{ public static void main(String[]args){ int[]x={0,1,2,3}; for{int i=0;i<3;1+=2){ try{ systcm.OUt.println(x[i+2]/x[i]+x[i+1]); }catch(ArithmeticException e){ System.OUt.println("errorl"): }catch(Exception e){ System.OUt.println("error2"): } } } }

    A.errorl

    B.error2

    C.errorl orror2

    D.2 error2


    正确答案:C
    C。【解析】当0作为除数时,会产生异常,而ArithmeticException和Exception两类异常都内部被捕捉到。

  • 第15题:

    阅读下列程序片段 Publicvoidtest(){ Try{ sayHello(); system.out.println(“hello"); }catch(ArrayIndexOutOfBoundExceptione){ System.out.println(“ArraylndexOutOfBoundException”); }catch(Exceptione){ System.out.println(“Exception”); }finally{ System.out.println(“finally”); } } 如果sayHello()方法正常运行,则test()方法的运行结果将是( )。

    A.Hello

    B.ArraylndexOutOfBondsException

    C.Exception Finally

    D.Hello Finally


    正确答案:D
    解析:sayHello()方法正常运行则程序不抛出异常,并走finally,所以为D。

  • 第16题:

    请阅读下列程序代码,然后将程序的执行结果补充完整。横线处应填写的内容是( )。 程序代码: 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两条信息。整个程序并未发生异常。

  • 第17题:

    public void test() {     try { oneMethod();  System.out.println("condition 1");  }  catch (ArrayIndexOutOfBoundsException e) {     System.out.println("condition 2");     }  catch(Exception e) {  System.out.println("condition 3");     }  finally {  System.out.println("finally");    }  }  Which will display if oneMethod run normally?()    

    • A、 condition 1
    • B、 condition 2
    • C、 condition 3
    • D、 finally

    正确答案:A,D

  • 第18题:

    public class A extends Thread {  A() {  setDaemon(true);  }  public void run() {  (new B()).start();  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“A done”);  }  class B extends Thread {  public void run() {  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“B done”);  }  }  public static void main(String[] args) {  (new A()).start();  }  }   What is the result?()  

    • A、 A done
    • B、 B done
    • C、 A done B done
    • D、 B done A done
    • E、 There is no exception that the application will print anything.
    • F、 The application outputs “A done” and “B done”, in no guaranteed order.

    正确答案:B

  • 第19题:

    public static void main(String[] args) {  try {  args=null;  args[0] = “test”;  System.out.println(args[0]);  } catch (Exception ex) {  System.out.println(”Exception”);  } catch (NullPointerException npe) {  System.out.println(”NullPointerException”);  }  }  What is the result?() 

    • A、 test
    • B、 Exception
    • C、 Compilation fails.
    • D、 NullPointerException

    正确答案:C

  • 第20题:

    public class Test {  public static void main(String[] args) {  int x = 0;  assert (x > 0): “assertion failed”;  System.out.println(“finished”);  }  }  What is the result?()  

    • A、 finished
    • B、 Compilation fails.
    • C、 An AssertionError is thrown.
    • D、 An AssertionError is thrown and finished is output.

    正确答案:A

  • 第21题:

    单选题
    public static void main(String[] args) {  try {  args=null;  args[0] = “test”;  System.out.println(args[0]);  } catch (Exception ex) {  System.out.println(”Exception”);  } catch (NullPointerException npe) {  System.out.println(”NullPointerException”);  }  }  What is the result?()
    A

     test

    B

     Exception

    C

     Compilation fails.

    D

     NullPointerException


    正确答案: D
    解析: 暂无解析

  • 第22题:

    单选题
    try {  if ((new Object))(.equals((new Object()))) {  System.out.println(“equal”);  }else{  System.out.println(“not equal”);  }  }catch (Exception e) {  System.out.println(“exception”);  }   What is the result? ()
    A

     equal

    B

     not equal

    C

     exception

    D

     Compilation fails.


    正确答案: C
    解析: 暂无解析

  • 第23题:

    单选题
    1. class Exc0 extends Exception { }  2. class Exc1 extends Exc0 { }  3. public class Test {  4. public static void main(String args[]) {  5. try {  6. throw new Exc1();  7. } catch (Exc0 e0) {  8. System.out.println(“Ex0 caught”);  9. } catch (Exception e) {  10. System.out.println(“exception caught”);  11. }  12. }  13. }  What is the result?()
    A

     Ex0 caught

    B

     exception caught

    C

     Compilation fails because of an error at line 2.

    D

     Compilation fails because of an error at line 6.


    正确答案: A
    解析: 暂无解析