publicclassfoo{publicstaticvoidmain(stringargs)try{return;}finally{system.out.printIn(Finally”);}}Whatistheresult?()

题目
publicclassfoo{publicstaticvoidmain(stringargs)try{return;}finally{system.out.printIn(Finally”);}}Whatistheresult?()

A.Theprogramrunsandprintsnothing.

B.Theprogramrunsandprints“Finally”

C.Thecodecompiles,butanexceptionisthrownatruntime.

D.Thecodewillnotcompilebecausethecatchblockismissing.

参考答案和解析
参考答案:B
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

【分录题】(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; } } }


B

第2题:

下面的程序段执行结果是 public class Foo { public static void main(String[] args) { try{ return; }finally { System.out.println("finally"); } } }

A.编译通过,但运行时出现异常

B.程序正常运行,不输出任何结果

C.程序正常运行,并输出“finally”

D.因为没有catch语句,编译错误


B

第3题:

下面程序段的执行结果是()。 public class Foo{ public static void main(String[] args){ try{ return; } finally { System.out.println("Finally!");} } }

A.程序正常运行,但不输出任何结果

B.程序正常运行,并输出Finally!

C.编译能通过,但运行时会出现例外

D.因为没有catch语句块,所以不能通过编译


B

第4题:

publicclassfoo{publicstaticvoidmain(Stringargs){Strings;system.out.printIn(s=”+s);}}Whatistheresult?()

A.Thecodecompilesand“s=”isprinted.

B.Thecodecompilesand“s=null”isprinted.

C.Thecodedoesnotcompilebecausestringsisnotinitialized.

D.Thecodedoesnotcompilebecausestringscannotbereferenced.

E.Thecodecompiles,butaNullPointerExceptionisthrownwhentoStringiscalled.


参考答案:C

第5题:

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

第6题:

publicclassFoo{publicstaticvoidmain(String[]args){try{return;}finally{System.out.println(Finally”);}}}Whatistheresult?()

A.Finally

B.Compilationfails.

C.Thecoderunswithnooutput.

D.Anexceptionisthrownatruntime.


参考答案:A

第7题:

publicclassfoo{publicstaticvoidmain(string[]args)try{return;}finally{system.out.printIn(Finally”);}}Whatistheresult?()

A.Theprogramrunsandprintsnothing.

B.Theprogramrunsandprints“Finally”

C.Thecodecompiles,butanexceptionisthrownatruntime.

D.Thecodewillnotcompilebecausethecatchblockismissing.


参考答案:B

第8题:

staticvoidtest(){try{Stringx=null;System.out.print(x.toString()+);}finally{System.out.print(finally);}}publicstaticvoidmain(String[]args){try{test();}catch(Exceptionex){System.out.print(”exception);}}Whatistheresult?()

A.null

B.finally

C.nullfinally

D.Compilationfails.

E.finallyexception


参考答案:E

第9题:

Given1.publicclassFoo{2.publicstaticvoidmain(String[]args)}3.try{return;}4.finally{Syste.out.printIn(Finally”);}5.}6.}Whatistheresult()?

A.Theprogramrunsandprintsnothing.

B.Theprogramrunsandprints“Finally”.

C.Thecodecomiles.Butanexceptionisthrownatruntime.

D.Thecodewillnotcompilebecausethecatchblockismissing.


参考答案:B