![2021年SCJP認(rèn)證考試題庫(kù)_第1頁(yè)](http://file4.renrendoc.com/view12/M0A/09/29/wKhkGWX4xh6AHE4lAAF5_6qI63Y124.jpg)
![2021年SCJP認(rèn)證考試題庫(kù)_第2頁(yè)](http://file4.renrendoc.com/view12/M0A/09/29/wKhkGWX4xh6AHE4lAAF5_6qI63Y1242.jpg)
![2021年SCJP認(rèn)證考試題庫(kù)_第3頁(yè)](http://file4.renrendoc.com/view12/M0A/09/29/wKhkGWX4xh6AHE4lAAF5_6qI63Y1243.jpg)
![2021年SCJP認(rèn)證考試題庫(kù)_第4頁(yè)](http://file4.renrendoc.com/view12/M0A/09/29/wKhkGWX4xh6AHE4lAAF5_6qI63Y1244.jpg)
![2021年SCJP認(rèn)證考試題庫(kù)_第5頁(yè)](http://file4.renrendoc.com/view12/M0A/09/29/wKhkGWX4xh6AHE4lAAF5_6qI63Y1245.jpg)
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
QUESTION61GIVENTHEEXHIBIT:Whichstatementistrue?A.Alloftheassertstatementsareusedappropriately.B.Onlytheassertstatementonline31isusedappropriatelyC.Theassertstatementsonlines29and31areusedappropriatelyD.Theassertstatementsonlines26and29areusedappropriatelyE.Theassertstatementsonlines29and33areusedappropriatelyF.Theassertstatementsonlines29,31and33areusedappropriatelyG.Theassertstatementsonlines26,29and31areusedappropriately斷言應(yīng)當(dāng)用在“你以為”你程序不也許產(chǎn)生錯(cuò)誤地方,并且有無(wú)啟用斷言,都不會(huì)影響程序正常運(yùn)營(yíng)。斷言使用限制:不要在public辦法中,用斷言來(lái)檢查參數(shù)對(duì)的性;不要讓斷言語(yǔ)句去解決某些程序必要流程。因素:1.public辦法會(huì)被別人調(diào)用,你不能保證她一定啟用斷言;如果沒(méi)有啟用,那么用斷言來(lái)做參數(shù)檢查也就沒(méi)故意義了。因此不要用斷言來(lái)檢查參數(shù),公共辦法參數(shù)一定要用代碼執(zhí)行檢查; 2.如果用斷言來(lái)控制程序執(zhí)行流程,如果沒(méi)有啟用斷言,那么程序就不能對(duì)的執(zhí)行下去。此外,斷言語(yǔ)句不可以有任何邊界效應(yīng),不要使用斷言語(yǔ)句去修變化量和變化辦法返回值,如果這樣當(dāng)啟動(dòng)斷言和不啟動(dòng)斷言執(zhí)行成果會(huì)截然不同。斷言使用時(shí)機(jī):檢查流程不變性:在if-elseswitch-case預(yù)期成果之外可以加上斷言做額外檢查。內(nèi)部執(zhí)行不變性:if(true){return;}assertfalse;檢查私有辦法參數(shù),成果等程序運(yùn)營(yíng)中一致性斷言語(yǔ)句不是永遠(yuǎn)會(huì)執(zhí)行,可以屏蔽也可以啟用
javac–source1.4*.java需要java–ea啟用assert;當(dāng)判斷條件為FALSE時(shí)就拋出錯(cuò)誤。Answer:(C)26行不適當(dāng):不要對(duì)public辦法參數(shù)斷言29適當(dāng):程序員在程序中最不大也許到達(dá)地方斷言
31適當(dāng):斷言private辦法參數(shù)
33行不適當(dāng):?jiǎn)⒂煤筒粏⒂脭嘌詴?huì)產(chǎn)生不同程序執(zhí)行序
參照大綱:異常解決—斷言和AssertionErrorQUESTION62GIVENTHEEXHIBIT:Whatistheresult?A. nullB. zeroC. someD. CompilationfailsE. AnexceptionisthrownatruntimeAnswer:(D)13行會(huì)報(bào)錯(cuò),應(yīng)在15行使用elseif參照大綱:流程控制QUESTION63Giventheexhibit:Whatistheresult?A.testB.ExceptionC.CompilationfailsD.NullPointerExceptionAnswer:(C)18行出錯(cuò),應(yīng)當(dāng)先catch子異常,再catchException;13行把a(bǔ)rgs賦null,14行會(huì)報(bào)NullPointerException如果沒(méi)有第13行運(yùn)營(yíng)時(shí)14行會(huì)報(bào)ArrayIndexOutOfBoundsException異常。參照大綱:異常解決QUESTION64Giventheexhibit:Whatistheresult?A.CompilationfailsB.aAaAaAaAAaaAaAC.AAaaAaAaAaaAaAD.AaAAAaaaAaAaAaE.aAaAaAaAaAAAaaF.AnexceptionisthrownatruntimeAnswer:(C)第10行將對(duì)strings這個(gè)集合做自然排序(ASCII小到大,一種一種比較)Collections.sort(Listlist)對(duì)list進(jìn)行排序,對(duì)set不能排序!List里可以放對(duì)象,因此當(dāng)list里面存儲(chǔ)是對(duì)象時(shí)候就不能用Collections.sort(Listlist)去排序了。由于JVM不懂得用什么規(guī)則去排序?。≈挥邪褜?duì)象類(lèi)實(shí)現(xiàn)Comparable接口,然后改寫(xiě)compareTo()參照大綱:集合QUESTION65Giventheexhibit:Whatistheresult?A.0B.1C.2D.3E.4F.Compilationfails.G.AnexceptionisthrownatruntimeAnswer:(D)Set中存儲(chǔ)元素是無(wú)序不重復(fù)。如果你想Set里Add一種元素,一方面她會(huì)去調(diào)用equals辦法,判斷set中與否有該元素,如果有則不更改set值并返回false,如果沒(méi)有,則把元素添加進(jìn)去,并返回true。Ws1ws2是自定義類(lèi),ws1和ws2equals不相等;Stringequals辦法已經(jīng)改寫(xiě),s1和s2相等;比較兩個(gè)對(duì)象與否相似,先比較hashcode,如果相似,在用equals辦法比較.如果都相似則兩個(gè)對(duì)象就以為是相似.Hashcode是把對(duì)象內(nèi)存地址通過(guò)運(yùn)算得來(lái).基本數(shù)據(jù)類(lèi)型和基本數(shù)據(jù)類(lèi)型包裝類(lèi)尚有String類(lèi)都已經(jīng)覆蓋了hashcode(),equals(),因此這些對(duì)象值只要同樣就以為對(duì)象同樣.參照大綱:集合QUESTION66Givenapre-genericsimplementationofamethod:Whichthreechangesmustbemadetothemethodsumtousegenerics?(choosethree)A.removeline14B.replaceline14with"inti=iter.next();"C.replaceline13with"for(inti:intList){"D.replaceline13with"for(Iteratoriter:intList)"E.replacethemethoddeclarationwith"sum(List<int>intList)"F.replacethemethoddeclarationwith"sum(List<Integer>intList)"Answer:(A,C,F(xiàn))publicstaticintsum(List<Integer>intList){intsum=0;for(inti:intList){ sum+=i;}returnsum;}參照大綱:集合和泛型Whatistheresult?A.Compilationfailsduetoanerrorinline23.B.Compilationfailsduetoanerrorinline29.C.AClassCastExceptationoccursinline29.D.AClassCastExceptationoccursinline31.E.Thevalueofallfourobjectprintsinnaturalorder.Answer:(C)Arrays.sort(Object[]a)辦法中,a每一種元素都必要是互相可以比較(調(diào)用pareTo(Objecto2))。否則會(huì)報(bào)ClassCastException異常。參照大綱:泛型QUESTION68PlacethecodeintopositiontocreateaclassthatmapsfromStringstoIntegervalues.Theresultofexecutionmustbe[one].Someoptionsmaybeusedmorethanonce.Answer:()publicclassNumberNames{ privateHashMap<String,Integer>map=newHashMap<String,Integer>(); publicvoidput(Stringname,Integervalue){ map.put(name,value); } publicSet<String>getNames(){ Returnmap.keySet(); }}QUESTION69Placearesultontoeachmethodcalltoindicatewhatwouldhappenifthemethodcallwereinsertedatline9.Note:Resultscanbeusedmorethanonce.Answer:()MethodResultm1(listA)Compilesandrunswithouterror泛型規(guī)范沒(méi)問(wèn)題m2(listA)Compilesandrunswithouterror泛型規(guī)范沒(méi)問(wèn)題m1(listB)CompilesandrunswithouterrorB是A子類(lèi),泛型規(guī)范沒(méi)問(wèn)題m2(listB)Doesnotcompilem1(listO)Doesnotcompilem2(listO)DoesnotcompileQUESTION70Giventheexhibit:Whatistheresult?A.apple:appleB.carrot:appleC.apple:bananaD.banana:appleE.carrot:carrotF.carrot:bananaAnswer:(C)PriorityQueue優(yōu)先級(jí)隊(duì)列:預(yù)設(shè)是自然排序,因而pq內(nèi)元素順序?qū)⑹莂pple->banana->carrotpoll()取第一種元素,取完之后刪除,peek取第一種元素,并不刪除元素QUESTION71Given:AprogrammerisdevelopingaclassKey,thatwillbeusedasakeyinastandardjava.util.HashMap.Whichtwomethodsshouldbeoverriddentoassurethatkeyworkscorrectlyasakey?(choosetwo)A.publicinthashCode()B.publicBooleanequals(Keyk)C.publicintcompareTo(Objecto)D.publicBooleanequals(Objecto)Answer:(A,D)HashMap中key不能重復(fù),因而必要實(shí)現(xiàn)hashCode和equals辦法QUESTION72---Giventheexhibit:Whichtwo,insertedatline2willallowthecodetocompile?(ChooseTwo)A.publicclassMinMax<?>{B.publicclassMinMax<?extendsNumber>{C.publicclassMinMax<NextendsObject>{D.publicclassMinMax<NextendsNumber>{E.publicclassMinMax<?extendsObject>{F.publicclassMinMax<NextendsInteger>{Answer:(D,F(xiàn))N是泛型類(lèi)別變量,它相稱于一種類(lèi)型。A 類(lèi)聲明是不能用?這個(gè)萬(wàn)用字符。B 同上C Object沒(méi)有doubleValue()辦法。D OK.E 同A。F OK.QUESTION73Giventheexhibit:enumExample{ONE,TWO,THREE}Whichstatementistrue?A.Theexpressions(ONE==ONE)andONE.equals(ONE)arebothguaranteedtobetrue.B.Theexpression(ONE<TWO)isguaranteedtobetrueandONE.compareTo(TWO)isguaranteedtobelessthanone.C.TheExamplevaluescannotbeusedinarawjava.util.HashMap.;instead,theprogrammermustuseajava.util.EnumMap.D.TheExamplevaluescanbeusedinajava.util.SortedSet,butthesetwillNOTbesortedbecauseenumeratedTypedoNOTIMPLEMENTjava.lang.Comparable.Answer:(A)A對(duì)的B不能保證C錯(cuò)誤枚舉類(lèi)型元素是可以用在HASHMAP里HashMap<Integer,Example>h=newHashMap<Integer,Example>;h.put(1,Example.ONE);D錯(cuò)誤,枚舉類(lèi)型元素值是可以放入SortedSet里例如TreeSet.把枚舉類(lèi)型元素轉(zhuǎn)成字符串在放入其中,字符串就已經(jīng)實(shí)現(xiàn)comparable接口。可以自然排序。SortedSet<Example>s=newTreeSet<Example>();s.add(Example.TWO);s.add(Example.ONE);System.out.println(s);打印出成果[ONE,TWO]QUESTION74Giventheexhibit:WhichlineofcodemarkstheearliestpointthatanobjectreferencedbyintObjbecomesacandidateforgarbagecollection?A.Line16B.Line17C.Line18D.Line19E.TheobjectisNOTacandidateforgarbagecollection.Answer:(D)intObj始終會(huì)被numbers引用,直到19行之后QUESTION75Given:Andthecommandlineinvocation:javaYippee2abcWhatistheresult?A.abB.bcC.abcD.Compilationfails.E.Anexceptionisthrownatruntime.Answer:(B)QUESTION76Aclassgames.cards.PokeriscorrectlydefinedinthejarfilePoker.jar.AuserwantstoexecutethemainmethodofPokeronaUNIXsystemusingthecommand:Javagames.cards.PokerWhatallowstheusertodothis?A.putPoker.jarindirectory/stuff/java,andsettheCLASSPATHtoinclude/stuff/javaB.putPoker.jarindirectory/stuff/java,andsettheCLASSPATHtoinclude/stuff/java/*.jarC.putPoker.jarindirectory/stuff/java,andsettheCLASSPATHtoinclude/stuff/java/Poker.jarD.putPoker.jarindirectory/stuff/java/games/cards,andsettheCLASSPATHtoinclude/stuff/javaE.putPoker.jarindirectory/stuff/java/games/cards,andsettheCLASSPATHtoinclude/stuff/java/*.jarF.putPoker.jarindirectory/stuff/java/games/cards,andsettheCLASSPATHtoinclude/stuff/java/Poker.jarAnswer:(C)classpath中須明確寫(xiě)明poker.jar,不能用*.jarQUESTION77Whichthreecodefragments,addedindividuallyatline29,producetheoutput100?(Choosethree.)A.n=100;B.i.setX(100);C.o.getY().setX(100);D.i=newInner();i.setX(100);E.0.setY(i);i=newInner();i.setX(100);F.i=newInner();i.setX(100);o.setY(i);Answer:(B,C,F(xiàn))依照內(nèi)存關(guān)系可知QUESTION78GivenaclassRepetition:AndgivenanotherclassDemo:Whichcodeshouldbeinsertedatline1ofDemo.javatocompileandrunDemotoprint"pizzapizza"A.importutils.*;B.staticimportutils.*;C.importutils.Repetition.*;D.staticimportutils.Repetition.*;E.importutils.Repetition.twice();F.importstaticutils.Repetition.twice;G.staticimportutils.Repetition.twice;Answer:(F)靜態(tài)import引入靜態(tài)辦法.importstaticutils..Repetition*;或者importstaticutils.Repetition.twice;A 正常導(dǎo)入類(lèi),Demo第5行要new實(shí)例才干帶用twice辦法.B staticimport順序顛倒,并且要加上class名C 正常導(dǎo)入,類(lèi)名背面不能跟*D 順序顛倒E 正常導(dǎo)入,只能導(dǎo)入包下類(lèi),不能導(dǎo)入類(lèi)里辦法.G 順序顛倒QUESTION79Given:Andtheinvocation:Whatistheresult?A.Anexceptionisthrownatruntime.B."Stringisempty"isprintedtooutput.C.Compilationfailsbecauseofanerrorinline12.D."Stringisnotempty"isprintedtooutput.Answer:(A)A空指針異常------------------“|”是非短路邏輯運(yùn)算符QUESTION80Exhibit:Giventhefully-qualifiedclassnames:com.foo.bar.Dogcom.foo.bar.blatz.Bookcom.bar.Carcom.bar.blatz.SunWhichgraphrepresentsthecorrectdirectorystructureforaJARfilefromwhichthoseclassescanbeusedbythecompilerandJVM?A.JarAB.JarBC.JarCD.JarDE.JarEAnswer:(A)QUESTION81Given:andtwoseparatecommandlineinvocations:javaYippeejavaYippee1234Whatistheresult?Nooutputisproduced.123B. Nooutputisproduced.234C. Nooutputisproduced.1234D. Anexceptionisthrownatruntime.123E. Anexceptionisthrownatruntime.234F. Anexceptionisthrownatruntime.1234Answer:(B)QUESTION82Given:Whatistheresult?A.CompilationfailsB.AnexceptionisthrownatruntimeC.doStuffx=6mainx=6D.doStuffx=5mainx=5E.doStuffx=5mainx=6F.doStuffx=6mainx=5Answer:(D)第10行參數(shù)x是值傳遞,不會(huì)變化main中x值。QUESTION83Given:WhenthedoSomethingmethodiscalled,afterwhichlinedoestheObjectcreatedinline5becomeavailableforgarbagecollection?A.Line5B.Line6C.Line7D.Line8E.Line9F.Line10Answer:(D)棧內(nèi)存用來(lái)存儲(chǔ)基本類(lèi)型變量和對(duì)象引用變量(對(duì)象地址)堆內(nèi)存用來(lái)存儲(chǔ)由new創(chuàng)立對(duì)象和數(shù)組QUESTION84Given:Whatistheresult?A. ExceptionB. A,B,ExceptionC. Compilationfailsbecauseofanerrorinline20.D. Compilationfailsbecauseofanerrorinline14.E. ANullPointerExceptionisthrownatruntime.Answer:(D)改寫(xiě)規(guī)定,子類(lèi)拋出異常要比父類(lèi)異常要小.本題中父類(lèi)沒(méi)有異常,子類(lèi)也不能有異常.QUESTION85Given:Whatistheresult?A.harrierB.shepherdC.retrieverD.CompilationfailsE.retrieverharrierF.Anexceptionisthrownatruntime.Answer:(D)18行,casedefault:語(yǔ)法錯(cuò)誤,應(yīng)改成default:QUESTION86Given:Whatistheresult?A. A,B,CB. B,C,AC. CompilationfailsD. ThecoderunswithnooutputE. AnexceptionisthrownatruntimeAnswer:(B)LinkedList有順序性,QUESTION87GivenWhatistheresult?A.endB.CompilationfailsC.exceptionendD.exceptiontestendE.AThrowableisthrownbymainF.AnExceptionisthrownbymainAnswer:(E)16行拋出Error,沒(méi)有捕獲。Throwable,Error和Exception都是她子類(lèi)QUESTION88Given:Whichthree,willmakecodeon37executeA.Theinstancegetsgarbagecollected.B.Thecodeonline33throwsanexception.C.Thecodeonline35throwsanexception.D.Thecodeonline31throwsanexception.E.Thecodeonline33executessuccessfully.Answer:(B,C,E)QUESTION89Given:Whatistheresult?A.CompilationfailsB.piisbiggerthan3.C.Anexceptionoccursatruntime.D.piisbiggerthan3.Haveaniceday.E.piisnotbiggerthan3.Haveaniceday.Answer:(A)18行finally是配合try使用.QUESTION90Given:Whichcode,insertedatline16willcauseajava.lang.ClassCastException?A.Alphaa=x;B.Foof=(Delta)x;C.Foof=(Alpha)x;D.Betab=(Beta)(Alpha)x;Answer:(B)轉(zhuǎn)到子類(lèi)別拋異常。.QUESTION91Givenamethodthatmustensurethatitsparameterisnotnull:What,insertedatline12,istheappropriatewaytohandleanullvalue?A.assertvalue==null;B.assertvalue!=null,"valueisnull";C.if(value==null){thrownewAssertionException("valueisnull");}D.if(value==null){thrownewIllegalArgumentException("valueisnull");}Answer:(D)A 不要用斷言對(duì)公共辦法參數(shù)進(jìn)行判斷B 同上C 沒(méi)有AssertionException這個(gè)類(lèi);AssertionError繼承自Error,handleerror是沒(méi)故意義D OK拋出參數(shù)錯(cuò)誤異常.QUESTION92PlacethecorrectCodeintheCodeSampletoachievetheexpectedresults.Expectedresults:Output:12481632CodeSampleAnswer:()for(intx:y){QUESTION93Given:WhichtwowillproduceanAssertionError?(Choosetwo.)A.javatestB.java-eatestC.javatestfile1D.java-eatestfile1E.java-eatestfile1file2F.java–ea:testtestfile1Answer:(B,E)QUESTION94Given:WhichstatementistrueifaResourceExceptionisthrownonline86?A.Line92willnotexecute.B.Theconnectionwillnotberetrievedinline85.C.Theresourceconnectionwillnotbeclosedonline88. D.Theenclosingmethodwillthrowanexceptiontoitscaller.Answer:(C)QUESTION95AssumingthattheserializeBanana()andthedeserializeBanana()methodswillcorrectlyuseJavaserializationandgiven:Whatistheresult?A.restore400B.restore403C.restore453D.Compilationfails.E.Anexceptionisthrownatruntime.Answer:(C)QUESTION96Given:Whatistheresult?A.CompilationfailsB.Piisapproximately3.C.Piisapproximately3.141593.D.Anexceptionisthrownatruntime.Answer:(D)%d打印一種整數(shù),規(guī)定接受一種整數(shù)拋IllegalFormatConversionExceptionQUESTION97Given:Whatistheresult?A.intLongB.ShortLongC.CompilationfailsD.Anexceptionisthrownatruntime.Answer:(A)QUESTION98Chaintheseconstructorstocreateobjectstoreadfromafilenamed"in"andtowritetoafilenamed"out".Answer:()newBufferedReader(newFileReader(“in”));newPrintWriter(newBufferedWriter(newFileWriter(“out”)));QUESTION99PlacethecodefragmentsintopositiontouseaBufferedReadertoreadinanentiretextfile.Answer:()classPrintFile{ publicstaticvoidmain(String[]args){ BufferedReaderbuffReader=null; //morecodeheretoinitializebuffReader try{ Stringtemp; while((temp=buffReader.readLine())!=null){ System.out.println(temp); } }catch(IOExceptione){ e.printStackTrace(); } }}QUESTION100Giventhismethodinaclass:Whichstatementistrue?A.ThiscodeisNOTthread-safe.B.TheprogrammercanreplaceStringBufferwithStringBuilderwithnootherchanges.C.Thiscodewillperformpoorly.Forbetterperformance,thecodeshouldberewritten:return"<"++">";D.ThiscodewillperformwellandconvertingthecodetouseStringBuilderwillnotenhancetheperformance.Answer:(B)QUESTION101Given:WhatcreatestheappropriateDateFormatobjectandaddsadaytotheDateobject?A. 35.Dateformatdf=Dateformat.getDateFormat();42.d.setTime((60*60*24)+d.getTime());B. 35.Dateformatdf=Dateformat.getDateInstance();42.d.setTime((1000*60*60*24)+d.getTime());C. 35.Dateformatdf=Dateformat.getDateFormat();42.d.setLocalTime((1000*60*60*24)+d.getLocalTime());D. 35.Dateformatdf=Dateformat.getDateInstance();42.d.setLocalTime((60*60*24)+d.getLocalTime());Answer:(B)轉(zhuǎn)換成求加1天后來(lái)改日期毫秒數(shù),再調(diào)用setTime()設(shè)立時(shí)間QUESTION102Given:WhichtwostatementsaretrueabouttheresultifthelocaleisLocale.US?(Choosetwo.)A.Thevalueofbis2.B.Thevalueofais3.14.C.Thevalueofbis2.00.D.Thevalueofais3.141.E.Thevalueofais3.1415.F.Thevalueofais3.1416.G.Thevalueofbis2.0000.Answer:(C,F(xiàn))QUESTION103Placethecorrectdescriptionofthecompileroutputonthecodefragmenttobeinsertedatline4and5.Thesamecompileroutputmaybeusedmorethanonce.Answer:()QUESTION104Given:Whichthreewillcompilesuccessfully?(Choosethree.)A.Objecto=Old.get0(newLinkedList());B.Objecto=Old.get0(newLinkedList<?>());C.Strings=Old.get0(newLinkedList<String>());D.Objecto=Old.get0(newLinkedList<Object>());E.Strings=(String)Old.get0(newLinkedList<String>());Answer:(A,D,E)B錯(cuò)誤<?>不應(yīng)出當(dāng)前這里C錯(cuò)誤get0()辦法回傳值是Object,因而不可賦值給StringQUESTION105Exhibit:Whichstatementistrueaboutthesetvariableonline12?A.Thesetvariablecontainsallsixelementsfromthecollcollection,andtheorderisguaranteedtobepreserved.B.Thesetvariablecontainsonlythreeelementsfromthecollcollection,andtheorderisguaranteedtobepreserved.C.Thesetvariablecontainsallsixelementsfromthecollcollection,buttheorderisNOTguaranteedtobepreserved.D.Thesetvariablecontainsonlythreeelementsfromthecollcollection,buttheorderisNOTguaranteedtobepreserved.Answer:(D)Set中元素是不能重復(fù),沒(méi)有順序QUESTION106Given:WhatistheappropriateddefinitionofthehashCodemethodinclassPerson?A.returnsuper.hashCode();B.returnname.hashCode()+age*7;C.returnname.hashCode()+comment.hashCode()/2;D.returnname.hashCode()+comment.hashCode()/2-age*3;Answer:(B)兩個(gè)equals對(duì)象,hashCode()應(yīng)當(dāng)相等,equals中是判斷age和name相等,因此hashCode也用age和name計(jì)算,A,C,D也許導(dǎo)致兩個(gè)相等對(duì)象,hashCode不相等QUESTION107Given:Whichstatementistrue?A.TheequalsmethoddoesNOTproperlyoverridetheObject.equalsmethod.B.Compilationfailsbecausetheprivateattributecannotbeaccessedinline5.C.Toworkcorrectlywithhash-baseddatastructures,thisclassmustalsoimplementthehashCodemethod.D.WhenaddingPersonobjectstojava.util.Setcollection,theequalsmethodinline4willpreventduplicates.Answer:(A)QUESTION108Given:Whichcode,insertedatline4,guaranteesthatthisprogramwilloutput[1,2]?A.Setset=newTreeSet();B.Setset=newHashSet();C.Setset=newSortedSet();D.Listset=newSortedList();E.Setset=newLinkedHashSet();Answer:(A)TreeSet可自動(dòng)排序,SortedSet是接口,不能實(shí)例化QUESTION109Given:What,insertedatline39,willsortthekeysinthepropsHashMap?A.Array.sort(s);B.s=newTreeSet(s);C.Collections.sort(s);D.s=newSortedSet(s);Answer:(B)QUESTION110Placecodeintotheclasssothatitcompilesandgeneratestheoutputanswer=42.Note:Codeoptionsmaybeusedmorethanonce.Answer:()publicclassGen<T>{ privateTobject; publicGen(Tobject){ this.object=object;}publicTgetObject(){ returnobject;}…}QUESTION111----------------???第一選項(xiàng)解釋Given:PlacetheCompilationResultsoneachcodestatementtoindicatewhetherornotthatcodewillcompileifinsertedintothetakeList()method.Answer:()List<String>StrList=newArrayList<String>();List<Integer>IntList=newArrayList<Integer>();List<?extendsObject>list;//該類(lèi)型泛型之能接受對(duì)象賦值,不能直接對(duì)該對(duì)象進(jìn)行add操作.//list.add(newObject());list=StrList;list=IntList;QUESTION112WhichtwocodefragmentswillexecutethemethoddoStuff()inaseparatethread?(Choosetwo.)A. newThread(){publicvoidrun(){doStuff();}};B. newThread(){publicvoidstart(){doStuff();}};C. newThread(){publicvoidstart(){doStuff();}}.run();D. newThread(){publicvoidrun(){doStuff();}}.start();E. newThread(newrunnable(){publicvoidrun(){doStuff();}}).run();F. newThread(newrunnable(){publicvoidrun(){doStuff();}}).start();Answer:(D,F(xiàn))D匿名類(lèi)別中復(fù)寫(xiě)run辦法,并調(diào)用start()辦法啟動(dòng)線程F運(yùn)用匿名實(shí)現(xiàn)runnable接口中run辦法,并調(diào)用start()啟動(dòng)線程QUESTION113Given:Whichtocanberesults?(Choosetwo.)A. java.lang.RuntimeException:ProblemB. run.java.lang.RuntimeException:ProblemC. Endofmethod.java.lang.RuntimeException:ProblemD. Endofmethod.run.java.lang.RuntimeException:ProblemE. run.java.lang.RuntimeException:ProblemEndofmethodAnswer:(D、E)在t中拋出RuntimeException,不干擾主線程執(zhí)行;QUESTION114----Given:Whichthreechangesshouldbemadetoadaptthisclasstobeusedsafelybymultiplethreads?(Choosethree.)A.declarereset()usingthesynchronizedkeywordB.declaregetName()usingthesynchronizedkeywordC.declaregetCount()usingthesynchronizedkeywordD.declaretheconstructorusingthesynchronizedkeywordE.declareincrement()usingthesynchronizedkeywordAnswer:(A,C,E)D選項(xiàng)錯(cuò)誤,由于構(gòu)造辦法不能用synchronized修飾name是final變量不會(huì)有多線程上維護(hù)問(wèn)題QUESTION115Given:Whichstatementistrue?A.CompilationfailsB.Anexceptionisthrownatruntime.C.Synchronizingtherun()methodwouldmaketheclassthread-safe.D.Thedatainvariable"x"areprotectedfromconcurrentaccessproblems.E.DeclaringthedoThings()methodasstaticwouldmaketheclassthread-safe.F.WrappingthestatementswithindoThings()inasy
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 海南職業(yè)技術(shù)學(xué)院《展示設(shè)計(jì)與策劃A》2023-2024學(xué)年第二學(xué)期期末試卷
- 武漢商貿(mào)職業(yè)學(xué)院《生產(chǎn)與運(yùn)作》2023-2024學(xué)年第二學(xué)期期末試卷
- 南昌師范學(xué)院《公共政策案例分析》2023-2024學(xué)年第二學(xué)期期末試卷
- 重慶建筑科技職業(yè)學(xué)院《工程熱力學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- 南通理工學(xué)院《園林植物組織培養(yǎng)》2023-2024學(xué)年第二學(xué)期期末試卷
- 內(nèi)蒙古北方職業(yè)技術(shù)學(xué)院《影視渲染技術(shù)》2023-2024學(xué)年第二學(xué)期期末試卷
- 榆林學(xué)院《特種電機(jī)及控制》2023-2024學(xué)年第二學(xué)期期末試卷
- 湖南信息學(xué)院《嵌入式系統(tǒng)課程設(shè)計(jì)》2023-2024學(xué)年第二學(xué)期期末試卷
- 《實(shí)驗(yàn)電阻的測(cè)量》課件
- 《資訊空中加油戰(zhàn)法》課件
- 綠植租擺服務(wù)投標(biāo)方案(技術(shù)方案)
- 經(jīng)濟(jì)人假設(shè)的歷史演變與現(xiàn)實(shí)選擇
- 安全教育培訓(xùn)記錄表(春節(jié)節(jié)后)
- 水稻葉齡診斷栽培技術(shù)課件
- 經(jīng)纖支鏡氣道球囊擴(kuò)張術(shù)課件
- 汽車(chē)尾氣污染與治理汽車(chē)尾氣污染課件
- 河南神火興隆礦業(yè)有限責(zé)任公司泉店煤礦礦產(chǎn)資源開(kāi)采與生態(tài)修復(fù)方案
- 對(duì)外漢語(yǔ)教學(xué)論
- 《十萬(wàn)個(gè)為什么》推進(jìn)課(小學(xué)課件)
- 全國(guó)主要城市的月日均總輻照量和年日均總輻照量
- 會(huì)計(jì)公司員工手冊(cè)
評(píng)論
0/150
提交評(píng)論