static void test() throws RuntimeException {  try {  System.out.print(”test “);  throw new RuntimeException();  }  catch (Exception ex) { System.out.print(”exception “); }  }  public static void main(String[] args) {  try { test(); }  catch (RuntimeExcept

题目

static void test() throws RuntimeException {  try {  System.out.print(”test “);  throw new RuntimeException();  }  catch (Exception ex) { System.out.print(”exception “); }  }  public static void main(String[] args) {  try { test(); }  catch (RuntimeException ex) { System.out.print(”runtime “); }  System.out.print(”end “);  }  What is the result?() 

  • A、 test end
  • B、 Compilation fails.
  • C、 test runtime end
  • D、 test exception end
  • E、 A Throwable is thrown by main at runtime.
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

static void test() {  try {  String x=null;  System.out.print(x.toString() +“ “);  }  finally { System.out.print(“finally “); }  }  public static void main(String[] args) {  try { test(); }  catch (Exception ex) { System.out.print(”exception “); }  }  What is the result?() 

  • A、 null
  • B、 finally
  • C、 null finally
  • D、 Compilation fails.
  • E、 finally exception

正确答案:E

第2题:

class ThreadExcept implements Runnable {   public void run() { throw new RuntimeException("exception "); }   public static void main(String [] args) {   new Thread(new ThreadExcept()).start();   try {   int x = Integer.parseInt(args[0]);   Thread.sleep(x);   System.out.print("main ");    } catch (Exception e) { }      }  }   和命令行:  java ThreadExcept 1000    哪一个是结果?()  

  • A、 main
  • B、 编译失败
  • C、 代码运行,但没有输出
  • D、 main java.lang.RuntimeException:exception

正确答案:D

第3题:

下列程序的运行结果是( )。 public class test{ private String[]data={¨10","10.5"); public void fun{ double s=0: for(int i=0;i<3;j++){ try{ s=s+Integer.parseInt(data[i]); catch(Exception e){ System.out.print("errorl:"+data[i]); } } } public static void main(string[]args){ try{ test d=new test: fun: }catch(Exception e){ System.OUt.println("error2") } } }

A.errorl:10.5

B.error2

C.errorl:10.5 error2

D.以上都不对


正确答案:C
C。【解析】try-catch块是可以嵌套分层的,并且通过异常对象的数据类型来进行匹配,以找到正确的catchblock异常错误处理代码。以下是通过异常对象的数据类型来进行匹配找到正确的catchblock的过程。①首先在抛出异常的try-catch块中查找catchblock,按顺序先与第一个catchblock块匹配,如果抛出的异常对象的数据类型与catchblock中传入的异常对象的临时变量(就是catch语句后面参数)的数据类型完全相同,或是它的子类型对象,则匹配成功,进入到catchblock中执行,否则到第2步;②如果有两个或更多的catchblock,则继续查找匹配第二个、第三个,直至最后一个catchblock,如匹配成功,则进入到对应的catchblock中执行,否则到第3步;③返回到上一级的try-catch块中,按规则继续查找对应的catchblock。如果找到,进入到对应的catchblock中执行,否则到第4步;④再到上上级的try-catch块中,如此不断递归,直到匹配到顶级的try-catch块中的最后一个catchblock,如果找到,进入到对应的catchblock中执行;否则程序将会执行terminate退出。所以本题选C。

第4题:

11.classA {  12. public void process() { System.out.print(”A “); } }  13. class B extends A {  14. public void process() throws RuntimeException {  15. super.process();  16. if (true) throw new RuntimeException();  17. System.out.print(“B”); }}  18. public static void main(String[] args) {  19. try { ((A)new B()).process(); }  20. catch (Exception e) { System.out.print(”Exception “); }  21. }  What is the result?() 

  • A、 Exception
  • B、 A Exception
  • C、 A Exception B
  • D、 A B Exception
  • E、 Compilation fails because of an error in line 14.
  • F、 Compilation fails because of an error in line 19.

正确答案:B

第5题:

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

第6题:

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

第7题:

public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”); }  catch (Exception ex) {  System.out.print(“B”);  }  finally {  System.out.print(“C”);  }  System.out.print(“D”);  }   public static void badMethod() {} }  What is the result?()  

  • A、 AC
  • B、 BD
  • C、 ACD
  • D、 ABCD
  • E、 Compilation fails.

正确答案:C

第8题:

现有:  class ThreadExcept implements Runnable  {  public void run()  {  throw new RuntimeException("exception ");  }  public static void main(Stri_ng  []  args)  {  new  Thread (new  ThreadExcept()).start();  try  {  int x=Integer.parselnt (args [0]);  Thread. sleep (x);  System.out.print("main");  } catch (Exception e)  {  }  }  }  和命令行:  java ThreadExcept l000     哪一个是结果?()    

  • A、main
  • B、编译失败
  • C、main java.lang.RuntimeException: exception
  • D、代码运行,但没有输出

正确答案:C

第9题:

现有:  class Flow {  public static void main(String [] args)   try {  System. out .print ("before") ;   doRiskyThing ( )  ;   System.out.print ("after ") ;   } catch (Exception fe) {  System.out.print ("catch") ;   }  System. out .println ( " done") ;  }  public static void doRiskyThing() throws Exception{   // this code returns unless it throws an Exception           }}  可能会产生哪两项结果 ?()  

  • A、 before catch
  • B、 before after done
  • C、 before catch done
  • D、 before after catch

正确答案:B,C

第10题:

public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”);  }  catch (RuntimeException ex) {  System.out.print(“B”);  }  catch (Exception ex1) {  System.out.print(“C”);  }   finally {  System.out.print(“D”);  }  System.out.print(“E”);  }  public static void badMethod() {  throw new RuntimeException();  }  }  What is the result?()  

  • A、 BD
  • B、 BCD
  • C、 BDE
  • D、 BCDE
  • E、 ABCDE
  • F、 Compilation fails.

正确答案:C

更多相关问题