您好,欢迎访问三七文档
SCJP模拟试题第1页SCJP模拟试题QuestionNo:11.Whichstatementaboutthegarbagecollectionmechanismaretrue?A.Garbagecollectionrequireadditionalprogramecodeincaseswheremultiplethreadsarerunning.B.Theprogrammercanindicatethatareferencethroughalocalvariableisnolongerofinterest.C.TheprogrammerhasamechanismthatexplicityandimmediatelyfreesthememoryusedbyJavaobjects.D.ThegarbagecollectionmechanismcanfreethememoryusedbyJavaObjectatexplectiontime.E.Thegarbagecollectionsystemneverreclaimsmemoryfromobjectswhilearestillaccessibletorunninguserthreads.答案:B、EQuestionNo:22.Givethefollowingmethod:1)publicvoidmethod(){2}Stringa,b;3}a=newString(“helloworld”);4}b=newString(“gameover”);5}System.out.println(a+b+”ok”);6}a=null;7}a=b;8}System.out.println(a);9}}Intheabsenceofcompileroptimization,whichistheearliestpointtheobjectareferedisdefinitelyelibiletobegarbagecollection.A.beforeline3B.beforeline5C.beforeline6D.beforeline7E.Beforeline9答案:DQuestionNo:33.Intheclassjava.awt.AWTEvent,whichistheparentclassuponwhichjdk1.1awteventsarebasedthereisamethodcalledgetIDwhichphraseaccuratelydescribesthereturnvalueofthismethod?A.Itisareferencetotheobjectdirectlyaffectedbythecauseoftheevent.B.Itisanindicationofthenatureofthecauseoftheevent.C.Itisanindicationofthepositionofthemousewhenitcausedtheevent.D.Inthecaseofamouseclick,itisanindicationofthetextunderthemouseatthetimeofSCJP模拟试题第2页theevent.E.Ittellsthestateofcertainkeysonthekeybordatthetimeoftheevent.F.Itisanindicationofthetimeatwhichtheeventoccurred.答案:BQuestionNo:44.Whichstatementaboutlisteneristrue?A.Mostcomponentallowmultiplelistenerstobeadded.B.Ifmultiplelistenerbeaddtoasinglecomponent,theeventonlyaffectedonelistener.C.Componentdon?tallowmultiplelistenerstobeadd.D.ThelistenermechanismallowsyoutocallanaddXxxxListenermethodasmanytimesasisneeded,specifyingasmanydifferentlistenersasyourdesignrequire.答案:A、DQuestionNo:55.Givethefollowingcode:publicclassExample{publicstaticvoidmain(Stringargs[]){intl=0;do{System.out.println(“Doingitforlis:”+l);}while(--l0)System.out.println(“Finish”);}}Whichwellbeoutput:A.Doingitforlis3B.Doingitforlis1C.Doingitforlis2D.Doingitforlis0E.Doingitforlis?C1F.Finish答案:D、FQuestionNo:66.Givethecodefragment:1)switch(x){2}case1:System.out.println(“Test1”);break;3}case2:4}case3:System.out.println(“Test2”);break;5}default:System.out.println(“end”);6}}whichvalueofxwouldcause“Test2”totheoutput:A.1SCJP模拟试题第3页B.2C.3D.default答案:B.CQuestionNo:77.Giveincompletedmethod:1)2){if(unsafe()){//dosomething…}3}elseif(safe()){//dotheother…}4}}Themethodunsafe()wellthroeanIOException,whichcompletesthemethodofdeclarationwhenaddedatlineone?A.publicIOExceptionmethodName()B.publicvoidmethodName()C.publicvoidmethodName()throwIOExceptionD.publicvoidmethodName()throwsIOExceptionE.publicvoidmethodName()throwsException答案:D、FQuestionNo:88.Givethecodefragment:if(x4){System.out.println(“Test1”);}elseif(x9){System.out.println(“Test2”);}else{System.out.println(“Test3”);}Whichrangeofvaluexwouldproduceofoutput“Test2”?A.x4B.x4C.x9D.None答案:DQuestionNo:99.Givethefollowingmethod:publicvoidexample(){try{unsafe();System.out.println(“Test1”);}catch(SafeExceptione){System.out.println(“Test2”);}finally{System.out.println(“Test3”);}System.out.println(“Test4”);SCJP模拟试题第4页Whichwilldisplayifmethodunsafe()runnormally?A.Test1B.Test2C.Test3D.Test4答案:A、C、DQuestionNo:1010.Whichmethodyoudefineasthestartingpointofnewthreadinaclassfromwhichnewthethreadcanbeexcution?A.publicvoidstart()B.publicvoidrun()C.publicvoidint()D.publicstaticvoidmain(Stringargs[])E.publicvoidrunnable()答案:BQuestionNo:1111.Giventhefollowingclassdefinition:classA{protectedinti;A(inti){this.i=i;}}whichofthefollowingwouldbeavalidinnerclassforthisclass?Selectallvalidanswers:A.classB{}B.classBextendsA{}C.classBextendsA{B(){System.out.println(“i=”+i);}}D.classB{classA{}}E.classA{}答案:AQuestionNo:12SCJP模拟试题第5页12.Whichmodifiershouldbeappliedtoamethodforthelockofobjectthistobeobtainedpriortoexcutionanyofthemethodbody?A.synchronizedB.abstractC.finalD.staticE.public答案:AQuestionNo:1313.ThefollowingcodeisentirecontentsofafilecalledExample.java,causespreciselyoneerrorduringcompilation:1)classSubClassextendsBaseClass{2}}3)classBaseClass(){4}Stringstr;5}publicBaseClass(){6}System.out.println(“ok”);}7}publicBaseClass(Strings){8}str=s;}}9)publicclassExample{10}publicvoidmethod(){11}SubClasss=newSubClass(“hello”);12}BaseClassb=newBaseClass(“world”);13}}14}}Whichlinewouldbecausetheerror?A.9B.10C.11D.12答案:CQuestionNo:1414.Whichstatementiscorrectlydeclareavariableawhichissuitableforreferingtoanarrayof50stringemptyobject?A.String[]aB.Stringa[]C.chara[][]D.Stringa[50]F.Objecta[50]答案:A、BQuestionNo:15SCJP模拟试题第6页15.Givethefollowingjavasourcefragement://pointxpublicclassInteresting{//dosomething}WhichstatementiscorrectlyJavasyntaxatpointx?A.importjava.awt.*;B.packagemypackageC.staticintPI=3.14D.publicclassMyClass{//dootherthing…}E.classMyClass{//dosomething…}答案:A、EQuestionNo:1616.Givethisclassoutline:classExample{privateintx;//restofclassbody…}AssumingthatxinvokedbythecodejavaExample,whichstatem
本文标题:SCJP模拟试题
链接地址:https://www.777doc.com/doc-4062077 .html