未分类题
ClassTestException1.publicclassTestExceptionextendsException{2.}Classa:1.publicclassa{2.3.publicStringsayHello(Stringname)throwsTestException{4.5.if(name==null){6.thrownewTestException();7.}8.9.returnHello+name;10.}11.12.}Aprogrammerwantstousethiscodeinanapplication:45.Aa=newA();46.System.out.println(a.sayHello(”John”));Whichtwoaretrue?()
A.Classawillnotcompile.
B.Line46canthrowtheuncheckedexceptionTestException.
C.Line45canthrowtheuncheckedexceptionTestException.
D.Line46willcompileiftheenclosingmethodthrowsaTestException.
E.Line46willcompileifenclosedinatryblock,whereTestExceptioniscaught.
A.publicclassTestExceptionextendsException{2.}Classa:1.publicclassa{2.3.publicStringsayHello(Stringname)throwsTestException{4.5.if(name==null){6.thrownewTestException();7.}8.9.returnHello+name;10.}11.12.}Aprogrammerwantstousethiscodeinanapplication:45.Aa=newA();46.System.out.println(a.sayHello(”John”));Whichtwoaretrue?()
A.Classawillnotcompile.
B.Line46canthrowtheuncheckedexceptionTestException.
C.Line45canthrowtheuncheckedexceptionTestException.
D.Line46willcompileiftheenclosingmethodthrowsaTestException.
E.Line46willcompileifenclosedinatryblock,whereTestExceptioniscaught.
【参考答案】
D, E