A.Theprogramrunsandprintsnothing.
B.Theprogramrunsandprints“Finally”
C.Thecodecompiles,butanexceptionisthrownatruntime.
D.Thecodewillnotcompilebecausethecatchblockismissing.
第1题:
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.
第2题:
下面程序段的执行结果是()。 public class Foo{ public static void main(String[] args){ try{ return; } finally { System.out.println("Finally!");} } }
A.程序正常运行,但不输出任何结果
B.程序正常运行,并输出Finally!
C.编译能通过,但运行时会出现例外
D.因为没有catch语句块,所以不能通过编译
第3题:
【分录题】(9-2)请阅读程序,写出程序运行结果。 public class Demo8 { public static void main(String args[]) { int b = get(); System.out.println(b); } public static int get() { try { return 1; } finally { return 2; } } }
第4题:
A.Thecodecompilesand“s=”isprinted.
B.Thecodecompilesand“s=null”isprinted.
C.Thecodedoesnotcompilebecausestringsisnotinitialized.
D.Thecodedoesnotcompilebecausestringscannotbereferenced.
E.Thecodecompiles,butaNullPointerExceptionisthrownwhentoStringiscalled.
第5题:
下面的程序段执行结果是 public class Foo { public static void main(String[] args) { try{ return; }finally { System.out.println("finally"); } } }
A.编译通过,但运行时出现异常
B.程序正常运行,不输出任何结果
C.程序正常运行,并输出“finally”
D.因为没有catch语句,编译错误