第四章练习题(异常)1.Java语言中异常的分类是哪项?A.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常2.所有异常的父类是哪项?A.ThrowableB.ErrorC.RuntimeExceptionD.Exception3.关于try...catch...finally结构,描述正确的是哪项?(选两项)A.可以有多个catchB.只能有一个catchC.可以没有catchD.finally必须有4.下列属于非受检异常的是哪项?A.SQLExceptionB.IOExceptionC.NullPointerExceptionD.OutOfMemoryError5.假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?A.raiseServiceExceptionB.thrownewServiceException()C.throwServiceExceptionD.throwsServiceException1-48-----------------------Page49-----------------------6.在方法的声明中,要求该方法必须抛出异常时使用哪个关键字?A.throwB.catchC.finallyD.throws7.现有:1.classNumber{2.publicstaticvoidmain(String[]aras){3.try{4.System.out.print(Integer.parselnt(forty));5.}catch(RuntimeExceptionr){6.System.out.print(runtime);7.}catch(NumberFormatExceptione){8.system..ut.print(number);9.}10.}11.}结果是什么?A.numberB.runtimeC.fortynumberD.编译失败8.现有:9.voidtopGo(){10.try{11.middleGo();12.)catch(Exceptione){13.System.out.print(catch);14.}15.}16.voidmiddleGo()throwsException{17.go();18.system.out.print(latemiddle);19.}2.voidgo()throwsExceptiOn{21.thrownewException();22.}1-49-----------------------Page50-----------------------如果调用topGo(),则结果为:A.latemiddleB.catchC.latemiddlecatchD.catchIatemiddle9.现有1.classCalc{2.publicstaticvoidmain(String[]args){3.try{4.intx=Integer.parselnt(42a);5.//insertcodehere6.System.out.print(oops);7.}8.}9.}下面哪两行分别插入到第五行,会导致输oops?(选两项)A.}catch(IllegalArgumentExceptione){B.}catch(IllegalStateExceptionc){C.}catch(NumbelFormatExceptionn){D.}catch(ClassCastExceptionc){10.现有:1.classFlow{2.publicstaticvoidmain(String[]args)t3.try{4.System.out.print(before);5.doRiskyThing();6.System.out.print(after);7.}catch(Exceptionfe){8.System.out.print(catch);9.}10.System.out.println(done);11.}12.publicstaticvoiddoRiskyThing()throwsException{13.//thiscodereturnsunlessitthrowsanException}}可能会产生哪两项结果?(选两项)A.beforecatchB.beforeafterdoneC.beforecatchdoneD.beforeaftercatch1-50-----------------------Page51-----------------------11.现有:1.classBirds{2.publicstaticvoidmain(String[]args){3.try{4.thrownewException();5.}catch(Exceptione){6.try{7.thrownewException();8.}catch(Exceptione2){System.out.print(inner);}9.System.out.print(middle);10.}11.System.out.print(outer);12.}13.}A.innerouterB.middleouterC.innermiddleouterD.编译失败12.现有:1.classParserextendsUtilis{2.publicstaticvoidmain(String[]args){3.try{System.out.print(newParser().getlnt(42));4.}catch(NumberFormatExceptionn){5.System.out.println(NFExc);}6.}7.intgetlnt(Stringarg)throwsNumberFormatException{8.returnInteger.parselnt(arg);9.}10.}11.classUtils{12.intgetlnt(Stringarg){return42;}13.}绐果为:A.NFExcB.42C.42NFExcD..编译失败1-51-----------------------Page52-----------------------13.现有:1.classParserextendsUtils(2.publicstaticvoidmain(String[]args){3.try{System.out.print(newParser().getlnt(42));4.}catch(Exceptione){5.System.out.println(Exc);}6.}7.intgetlnt(Stringarg)throwsException(8.returnInteger.parselnt(arg);9.}10.}11.classUtils{12.intgetlnt(Stringarg){return42;}13.}结果为:A.42B.ExcC.42ExcD.编译失败14.现有:1.classPropeller2{2.pulolicstaticvoidmain(String[]args)//addcodehere?3.{newPropeller2().topGo();}4.5.voidtopGo()//addcodehere?6.{middleGo();}7.8.voidmiddleGo()//addcodehere?9.{go();System.out.println(latemiddle);}voidgo()//addcodehere?12.{thrownewException();}13.}为使代码通过编译,需要在哪一行加入声明throwsException?A.只在第11行B.在第8行和第11行C.在第5行、第8行和第11行D.在第2行、第5行、第8行和第11行1-52-----------------------Page53-----------------------15.现有1.classParserextendsUtils{2.publicstaticvoidmain(String[]args){3.try{System.out.print(newParser().getlnt(42))4.}catch(Exceptione){5.System.out.println(Exc);}6.}7.intgetlnt(Stringarg)throwsException{8.returnInteger.parselnt(arg);9.}10.}11.classUtils{12.intgetlnt(){return42;}13.}结果是什么?A.42ExcB.ExcC.42D.编译失败1-53-----------------------Page54-----------------------参考答案1B2A3AC4D5B6D7D8B9AC10BC11C12B13D14D15C