before catch
before after done
before catch done
before after catch
第1题:
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?()
第2题:
public class TestApp{ public static void main(String[] args){ try{ int i = 0; int j = 1 / i; System.out.println(“1”); } catch(Exception e){ System.out.print(“3”); } finally{ System.out.print(“4”); } } } 上述程序运行后的输出是哪项?()
第3题:
classFlow{publicstaticvoidmain(String[]args){try{System.out.print("before");doRiskyThing();System.out.print("after");}catch(Exceptionfe){System.out.print("catch");}System.out.println("done");}publicstaticvoiddoRiskyThing()throwsException{//thiscodereturnsunlessitthrowsanException}}可能会产生下面哪两项结果?()
A.before
B.beforecatch
C.beforeafterdone
D.beforecatchdone
第4题:
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?()
第5题:
public class X { public static void main(String [] args) { try { badMethod(); System.out.print(“A”); } catch (Exception ex) { System.out.print(“C”); } finally { System.out.print(“B”); } System.out.print(“D”); } public static void badMethod() { throw new Error(); } } What is the result?()
第6题:
class Order implements Runnable { public void run() { try { Thread.sleep(2000); } catch (Exception e) { } System.out.print("in "); } public static void main(String [] args) { Thread t = new Thread(new Order()); t.start(); System.out.print("pre "); try { t.join(); } catch (Exception e) { } System.out.print("post "); } } 可产生哪两项结果?()
第7题:
class Number { public static void main(String [] args) { try { System.out.print(Integer.parseInt("forty ")); } catch (RuntimeException r) { System.out.print("runtime "); } catch (NumberFormatException e) { System.out.print("number "); } } } 结果是什么?()
第8题:
现有:classFlow{publicstaticvoidmain(String[]args)try{System.out.print("before");doRiskyThing();System.out.print("after");}catch(Exceptionfe){System.out.print("catch");}System.out.println("done");}publicstaticvoiddoRiskyThing()throwsException{//thiscodereturnsunlessitthrowsanException}}可能会产生哪两项结果?()
A.beforecatch
B.beforeafterdone
C.beforecatchdone
D.beforeaftercatch
第9题:
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?()
第10题:
现有: 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 }} 可能会产生哪两项结果 ?()