Java_SCJP_Marcus_Green_SCJP_Exam_2

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

JavaProgrammerCertificationMockExamNo2Lastupdated29Dec200260QuestionsCopyright©MarcusGreen2002BuyJavaCertificationbookscontaingmoremockexamsat(mail@marcusgreen.co.uk)andmaybefreelydistributedsolongasitisunmodified.Pleaseemailmeifyouhaveanycorrectionsorcomments,butpleasereadthisdocumentfirst://://(around35pagesifyouweretoprintitout),ifyoucannotseetheanswersthenyouhavenotgottheentiredocument,tryreloadingituntillyoucanseetheanswertoQuestion60andthewordsEndofdocument.Ifyoucannotloaditjustkeeptrying.Theanswerscontainreferencestoapproximatelywhichobjectivethequestionrelatesto.Ifyouhaveaqueryaboutanyofthesequestions,please,pleaseincludethefullanswerwiththequestion.Youcanjumpbackfromananswertothequestionbypressingthebackbuttononyourwebbrowser.Howdoesthiscomparewiththerealthing?Asof5Oct2000thequestionformathaschangedveryslightly.Youwillnowgetmorequestionsthatincludesnippetsofcode(thoughtheratiomaybesimilartothismockexam).Eachquestionwillalsotellyouhowmanyoftheoptionsyouneedtopick.Youcanreadmoreabouttheserevisionsat://://://)Whatwillhappenwhenyouattempttocompileandrunthiscode?abstractclassBase{abstractpublicvoidmyfunc();publicvoidanother(){System.out.println(Anothermethod);}}publicclassAbsextendsBase{publicstaticvoidmain(Stringargv[]){Absa=newAbs();a.amethod();}publicvoidmyfunc(){System.out.println(MyFunc);}publicvoidamethod(){myfunc();}}1)Thecodewillcompileandrun,printingoutthewordsMyFunc2)ThecompilerwillcomplainthattheBaseclasshasnonabstractmethods3)ThecodewillcompilebutcomplainatruntimethattheBaseclasshasnonabstractmethods4)Thecompilerwillcomplainthatthemethodmyfuncinthebaseclasshasnobody,nobodyatalltoloooveitAnswertoQuestion1Question2)Whatwillhappenwhenyouattempttocompileandrunthiscode?publicclassMyMain{publicstaticvoidmain(Stringargv){System.out.println(Hellocruelworld);}}1)Thecompilerwillcomplainthatmainisareservedwordandcannotbeusedforaclass2)ThecodewillcompileandwhenrunwillprintoutHellocruelworld3)Thecodewillcompilebutwillcomplainatruntimethatnoconstructorisdefined4)ThecodewillcompilebutwillcomplainatruntimethatmainisnotcorrectlydefinedAnswertoQuestion2Question3)WhichofthefollowingareJavamodifiers?1)public2)private3)friendly4)transient5)vagrantAnswertoQuestion3Question4)Whatwillhappenwhenyouattempttocompileandrunthiscode?classBase{abstractpublicvoidmyfunc();publicvoidanother(){System.out.println(Anothermethod);}}publicclassAbsextendsBase{publicstaticvoidmain(Stringargv[]){Absa=newAbs();a.amethod();}publicvoidmyfunc(){System.out.println(Myfunc);}publicvoidamethod(){myfunc();}}1)Thecodewillcompileandrun,printingoutthewordsMyFunc2)ThecompilerwillcomplainthattheBaseclassisnotdeclaredasabstract.3)ThecodewillcompilebutcomplainatruntimethattheBaseclasshasnonabstractmethods4)Thecompilerwillcomplainthatthemethodmyfuncinthebaseclasshasnobody,nobodyatalltoloooveitAnswertoQuestion4Question5)Whymightyoudefineamethodasnative?1)TogettoaccesshardwarethatJavadoesnotknowabout2)Todefineanewdatatypesuchasanunsignedinteger3)TowriteoptimisedcodeforperformanceinalanguagesuchasC/C++4)ToovercomethelimitationoftheprivatescopeofamethodAnswertoQuestion5Question6)Whatwillhappenwhenyouattempttocompileandrunthiscode?classBase{publicfinalvoidamethod(){System.out.println(amethod);}}publicclassFinextendsBase{publicstaticvoidmain(Stringargv[]){Baseb=newBase();b.amethod();}}1)Compiletimeerrorindicatingthataclasswithanyfinalmethodsmustbedeclaredfinalitself2)Compiletimeerrorindicatingthatyoucannotinheritfromaclasswithfinalmethods3)RuntimeerrorindicatingthatBaseisnotdefinedasfinal4)Successincompilationandoutputofamethodatruntime.AnswertoQuestion6Question7)Whatwillhappenwhenyouattempttocompileandrunthiscode?publicclassMod{publicstaticvoidmain(Stringargv[]){}publicstaticnativevoidamethod();}1)Erroratcompilation:nativemethodcannotbestatic2)Erroratcompilationnativemethodmustreturnvalue3)Compilationbuterroratruntimeunlessyouhavemadecodecontainingnativeamethodavailable4)CompilationandexecutionwithouterrorAnswertoQuestion7Question8)Whatwillhappenwhenyouattempttocompileandrunthis

1 / 52
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功