您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 资本运营 > 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
本文标题:Java_SCJP_Marcus_Green_SCJP_Exam_2
链接地址:https://www.777doc.com/doc-6372376 .html