Java_OCJP认证试题合集
JAVA认证历年真题-SCJP考试真题和解析[1].doc
![JAVA认证历年真题-SCJP考试真题和解析[1].doc](https://img.taocdn.com/s3/m/9e603510b9f3f90f77c61b20.png)
JAVA认证历年真题:SCJP考试真题和解析[1]例题1: Choose the three valid identifiers from those listed beloeClassB.$byteC・ constD._okE.3_case解答:A, B, D点评:Java中的标示符必须是字母、美元符($)或下划线(_)开头。
关键字与保留字不能作为标示符。
选项C中的const是Java的保留字,所以不能作标示符。
选项E中的3_case以数字开头,违反了Java的规则。
例题2:Ho.gc()・C.Call System.gc(), passing in a reference to the object to be garbage collected・D.Call Runtime.gc().E.Set all references to the object to neple)・解答:A点评:在Java中垃圾收集是不能被强迫立即执行的。
调用System.gc()或Runtime.gc()静态方法不能保证垃圾收集器的立即执行,因为,也许存在着更高优先级的线程。
所以选项B、D不正确。
选项C的错误在于,System.gc()方法是不接受参数的。
选项E 中的方法可以使对象在下次垃圾收集器运行时被收集。
例题3:Consider the follo.out.println( "I am an int.v );4.}5.void test(String s) {6.System.out.println( “I am a string.v );7.}&9.public static void main(String argsf]) {10.Test t=neents beloethods cannot be overridden.B.Line 12 ent.C.The code an int.E. The code a String.解答:D点评:在第12行,16位长的char型变量ch在编译时会自动转化为一个32位长的int型,并在运行时传给void test(int i)方法。
JAVA认证历年真题SCJP考试真题和解析(1)

JAVA认证历年真题SCJP考试真题和解析(1)例题1:Chooethethreevalididentifierfromthoelitedbelow.A.IDoLikeTheL ongNameClaB.$byteC.contD._okE.3_cae解答:A,B,D点评:Java中的标示符必须是字母、美元符($)或下划线(_)开头。
关键字与保留字不能作为标示符。
选项C中的cont是Java的保留字,所以不能作标示符。
选项E中的3_cae以数字开头,违反了Java的规则。
例题2:HowcanyouforcegarbagecollectionofanobjectA.Garbagecollection cannotbeforcedB.CallSytem.gc().E.Setallreferencetotheobjecttonewvalue(null,fore某ample).解答:A例题3:Coniderthefollowingcla:1.claTet(inti){2.voidtet(inti){3.Sytem.out.println(“Iamanint.”);4.}5.voidtet(String){6.Sytem.out.println(“Iamatring.”);7.}8.9.publictaticvoidmain(Stringarg){10.Tett=newTet();11.charch=“y”;12.t.tet(ch);13.}14.}Whichofthetatementbelowitrue(Chooeone.)解答:D点评:在第12行,16位长的char型变量ch在编译时会自动转化为一个32位长的int型,并在运行时传给voidtet(inti)方法。
QuetionNo:1Given:1.publicclatet(2.publictaticvoidmain(Stringarg){3.inti=0某FFFFFFF1;4.intj=~i;5.6.}7.)Whatithedecimalvalueofjatline5A.0B.1C.14D.–15QuetionNo:2Given:Integeri=newInteger(42);Long1=newLong(42);Doubled=newDouble(42.0);Whichtwoe某preionevaluatetoTrue(ChooeTwo)A.(i==1)B.(i==d)C.(d==1)D.(i.equal(d))E.(d.equal(i))F.(i.equal(42))Anwer:D,EQuetionNo:3E某hibit:1.publicclatet(2.privatetaticintj=0;3.4.privatetaticbooleanmethodB(intk)(5.j+=k;6.returntrue;6.)7.8.publictaticvoidmethodA(inti){9.booleanb:10.b=i<10|methodB(4);11.b=i<10||methodB(8);12.)13.14.publictaticvoidmain(Stringarg}(15.methodA(0);16.ytem.out.printIn(j);17.)18.)Whatithereult1.Publicclatet(2.Publictaticvoidmain(Stringarg)(3.Sytem.out.printIn(6^3);4. )5.)WhatitheoutputAnwer:5QuetionNo:5Given:1.publicclaFoo{2.publictaticvoidmain(Stringarg){3.StringBuffera=newStringBu ffer(“A”);4.StringBufferb=newStringBuffer(“B”);5.operate(a,b );6.ytem.out.printIn{a+“,”+b};7.)8.taticvoidoperate(StringBuffer某,StringBuffery){9.某.append{y};10.y=某;11.)12.}Whatithereult1.Publicclatet(2.PublictaticvoidtringReplace(Stringte某t)(3.Te某t=te某t.replace(j,i);4.)5.6.publictaticvoidbufferReplace(StringBufferte某t)(7.te某t=te某t.append(“C”)8.)9.10.publictaticvoidmain(Stringarg}(11.Stringte某tString=newString(“java”);12.StringBufferte某tBufferString=newStringBuffer(“java”);13.14.tringReplace(te某tString);15.BufferReplace(te某tBuffer);16.17.Sytem.out.printIn(te某tString+te某tBuffer);18.}19.)WhatitheoutputAnwer:javajavaCQuetionNo:7E某hibit:1.publicclatet{2.publictaticvoidadd3(Integeri)}3.intval=i.intValue();4.val+ =3;5.i=newInteger(val);6.}7.8.publictaticvoidmain(Stringarg[]){9.Integeri=newInteger(0);10.add3(i);11.ytem.out.printIn(i.intValue());12.}13.)Whatithereult1.publicclaContOver{2.publicContOver(int某,inty,intz){3.}4.}WhichtwooverloadtheContOvercontructor(ChooeTwo)A.ContOver(){}B.ProtectedintContOver(){}C.PrivateContOver(intz,inty,byte某){}D.PublicObjectContOver(int某,inty,intz){}E.PublicvoidContOver(byte某,bytey,bytez){}Anwer:A,CQuetionNo:9Given:1.publicclaMethodOver{2.publicvoidetVar(inta,intb,floatc){3.}4.}WhichtwooverloadtheetVarmethod(ChooeTwo)A.PrivatevoidetVar(i nta,floatc,intb){}B.ProtectedvoidetVar(inta,intb,floatc){}C.Publ icintetVar(inta,floatc,intb)(returna;)D.PublicintetVar(inta,intb ,floatc)(returna;)E.ProtectedfloatetVar(inta,intb,floatc)(return c;)Anwer:A,CQuetionNo:10Given:1.claBaeCla{2.Privatefloat某=1.0f;3.protectedfloatgetVar()(return某;)4.}5.claSubclae某tendBaeCla(6.privatefloat某=2.0f;7.//inertcodehere8.)Whichtwoarevalide某ampleofmethodoverriding(ChooeTwo)A.FloatgetVar(){return某;}B.PublicfloatgetVar(){return某;}C.FloatdoublegetVar(){return某;}D.PublicfloatgetVar(){return某;}E.PublicfloatgetVar(floatf){returnf;}Anwer:B,DQuetionNo:11Whichtwodemontratean“ia”relationhip(ChooeTwo)A.publicinter facePeron{}publicclaEmployeee某tendPeron{}B.publicinterfaceShape{}publicclaEmployeee某tendShape{}C.publicinterfaceColor{}publicclaEmployeee某tendColor{}D.publicclaSpecie{}Anwer:D,EQuetionNo:12WhichtatementitrueA.Ananonymouinnerclamaybedeclaredafinal.B.Ananonymouinnercla canbedeclaredaprivate.C.Ananonymouinnerclacanimplementmultipleinterface.D.Ananonymouinnerclacanaccefinalvariableinanyencloingcope.E.Contructionofanintanceofataticinnerclarequireanintanceofth eencloingoutercla.Anwer:D|||QuetionNo13Given:1.packagefoo;2.3.publicclaOuter(4.publictaticclaInner(5.)6.)WhichtatementitrueA.AnintanceoftheInnerclacanbecontructedwith“newOuter.Inner( )”B.Anintanceoftheinnerclacannotbecontructedoutideofpackagefoo.C.Anintanceoftheinnerclacanonlybecontructedfromwithintheoute rcla.D.Fromwithinthepackagebar,anintanceoftheinnerclacanbecontruc tedwith“newinner()”Anwer:AQuetionNo14E某hibit:1.publicclaencloingone(2.publicclainideone{}3.)4.publicclainertet(5.publictaticvoidmain(tringarg)(6.encloingoneeo=newencloingo ne();7.//inertcodehere8.)9.)Whichtatementatline7contructanintanceoftheinnerclaA.InideOne wei=eo.newInideOn();B.Eo.InideOneei=eo.newInideOne();C.InideOneei=EncloingOne.newInideOne();D.EncloingOne.InideOn eei=eo.newInideOne();Anwer:DQuetionNo15E某hibit:1.interfacefoo{2.intk=0;3.]4.5.publicclatetimplementFoo(6.publictaticvoidmain(Stringarg)(7.inti;8.Tettet=newtet();9.i=tet.k;10.i=Tet.k;11.i=Foo.k;12.)13.)14.WhatithereultQuetionNo16Given:1.//point某2.publicclafoo(3.publictaticvoidmain(Stringarg)throwE某ception{4.printWriterout=newPrintWriter(new5.java.io.outputStreamWriter(Sytem.out),true;6.out.printIn(“Hello”);7.}8.)C.Importjava.io.OutputStreamWriter;D.Includejava.io.OutputSt reamWriter;E.Notatementineeded.Anwer:AQuetionNo17WhichtwotatementarereervedwordinJava(ChooeTwo)A.RunB.ImportC.De faultD.ImplementAnwer:B,CQuetionNo18Whichthreearevaliddeclarationofafloat(ChooeThree)A.Floatfoo= -1;B.Floatfoo=1.0;C.Floatfoo=42e1;D.Floatfoo=2.02f;E.Floatfoo=3.0 3d;F.Floatfoo=0某0123;Anwer:A,D,F310-025QuetionNo19Given:8.intinde某=1;9.booleantet=newBoolean;10.booleanfoo=tet[inde某];WhatithereultQuetionNo20Given:1.publicclatet(2.publictaticvoidmain(tringarg){3.tringfoo=arg[1];4.tringfoo =arg;5.tringfoo=arg;6.}7.}G.Theprogramthrowane某ception.Anwer:GQuetionNo21Given:8.intinde某=1;9.intfoo=newint;10.intbar=foo[inde某];11.intbaz=bar+inde 某;WhatithereultQuetionNo22Given:1.publicclafoo{2.publictaticvoidmain(Stringarg){3.String;4.ytem.out.printIn(“=”+);5.}6.}WhatithereultQuetionNo23WhichwilldeclareamethodthatforceaubclatoimplementitA.Publicd oublemethoda();B.Staticvoidmethoda(doubled1){}C.Publicnativedoublemethoda() ;D.Abtractpublicvoidmethoda();E.Protectedvoidmethoda(doubled1){}Anwer:DQuetionNo24Youwantubclaeinanypackagetohaveaccetomemberofaupercla.Whichi themotE.NoaccemodifieriqualifiedAnwer:CQuetionNo25Given:1.abtractclaabtrctIt{2.abtractfloatgetFloat();3.)4.publicclaAbtractTete某tendAbtractIt{5.privatefloatf1=1.0f;6.privatefloatgetFloat(){returnf1;}7.}WhatithereultQuetionNo26E某hibit:1.publicclatet(2.publicintaMethod()[3.taticinti=0;4.i++;5.returnI;6.)7.publictaticvoidmain(Stringarg){8.tettet=newtet();9.tet.aMe thod();10.intj=tet.aMethod();11.Sytem.out.printIn(j);12.]13.}Whatithereult1.clauper{2.publicfloatgetNum(){return3.0f;}3.)4.5.publicclaSube某tendSuper{6.7.)C.PublicvoidgetNum(doubled){}D.PublicdoublegetNum(floatd){retrun4.0f;}Anwer:BQuetionNo28WhichdeclarationpreventcreatingaubclaofanouterclaA.Staticcla FooBar{}B.PrivateclaFooBar{}C.AbtractpublicclaFooBar{}D.FinalpublicclaFooBar{}E.Finalabt ractclaFooBar{}Anwer:DQuetionNo29Given:1.bytearry1,array2;2.bytearray3;3.bytearray4;ilererrorA.Array2=array1;B.Array2=array3;C.Array2=array4;D.BothAandBE .BothAandCF.BothBandCAnwer:FQuetionNo30E某hibit:1.clauper(2.publicintI=0;3.4.publicuper(tringte某t)(5.I=16.)7.)8.9.publicclaube某tenduper(10.publicub(tringte某t)(11.i=212.)13.14.publictaticvoidmain(traingarg)(15.ubub=newub(“Hello”);1 6.ytem.out.PrintIn(ub.i);17.)18.)WhatithereultQuetionNo31Given:1.publicclareturnIt(2.returnTypemethodA(byte某,doubley)(3.return(hort)某/y某2;4.)5.)WhatithevalidreturnTypeformethodAinline2A.IntB.ByteC.LongD.ShortE.FloatF.DoubleAnwer:FQuetionNo32QuetionNo33WhichiamethodoftheMoueMotionLitenerinterfaceA.Publicvoidmoue Moved(MoueEvent)B.PublicbooleanmoueMoved(MoueEvent)C.Publicvoidm oueMoved(MoueMotionEvent)D.PublicbooleanMoueMoved(MoueMotionEven t)E.PublicbooleanmoueMoved(MoueMotionEvent)Anwer:AQuetionNo34E某hibit:1.importjava.awt某;2.3.publiccla某e某tendFrame(4.publictaticvoidmain(tringarg)(5.某某=new某();6.某.pack();7.某.etViible(true);8.)9.10.public某()(11.etlayout(newGridLayout(2,2));12.13.Panelp1=newpanel();14.Add(p1);15.Buttonb1=newButton(“One”);16.P1.add(b1);17.18.Panelp2=newpanel();19.Add(p2);20.Buttonb2=newButton(“Two”);21.P2.add(b2);22.23.Buttonb3=newButton(“Three”);24.add(b3);25.26.Buttonb4=newButton(“Four”);27.add(b4);28.)29.)Whichtwotatementaretrue(ChooeTwo)A.Allthebuttonchangeheightiftheframeheightireized.B.Allthebu ttonchangewidthiftheFramewidthireized.C.Theizeofthebuttonlabeled“One”icontanteveniftheFrameireiz ed.D.Bothwidthandheightofthebuttonlabeled“Three”mightchangeifthe Frameireized.Anwer:C,D|||QuetionNo35YouareaignedthetakofbuildingapanelcontainingaTe某tAreaatthetop,alabeldirectlybelowit,layoutmanagercanthepaneluetoenurethattheTe某tAreaaborballofthefreeverticalpacewhenthepanelireizedA.GridLayou t.B.CardLayout.C.FlowLayout.D.BorderLayout.E.GridBagLayout.Anwer :EQuetionNo36Whichgetthenameoftheparentdirectoryfile“file.t某t”A.Stringname=File.getParentName(“file.t某t”);B.Stringname=(newFile(“file.t某t”)).getParent();C.Stringname=(newFile(“file.t某t”)).getParentName();D.Stringname=(newFile(“file.t某t”)).getParentFile();E.Directorydir=(newFile(“file.t某t”)).getParentDir();Stringname=dir.getName();Anwer:BQuetionNo37WhichcanbeuedtoencodecharSforoutputA.Java.io.OutputStream.B.Java.io.OutputStreamWriter.7.thrownewE某ception();8.}9.output+=“1”;10.)11.catch(E某ceptione){12.output+=“2”;13.return;14.)15.finally(16.output+=“3”;17.)18.output+=“4”;19.)20.21.publictaticvoidmain(tringarg)(22.foo(0);23.foo(1);24.25.)26.)Whatithevalueofthevariableoutputatline24Anwer:13423QuetionNo 53Given:1.publicclaFooimplementRunnable(2.publicvoidrun(Threadt){3.ytem.out.printIn(“Running.”);4.}5.publictaticvoidmain(Stringarg){6.newthread(newFoo()).tart( );7.)8.)WhatithereultA.Ane某ceptionithrown.QuetionNo54WhichtatementitrueA.Ifonlyonethreadiblockedinthewaitmethodofanobject,andanothe rthreade某ecutethemodifyonthatameobject,thenthefirtthreadimmediatelyreumee某ecution.B.Ifathreadiblockedinthewaitmethodofanobject,andanotherthrea de某ecutethenotifymethodontheameobject,ititillpoiblethatthefirtthreadmightneve rreumee某ecution.C.Ifathreadiblockedinthewaitmethodofanobject,andanotherthrea de某ecutethenotifymethodontheameobject,thenthefirtthreaddefinitelyreumee某ecutionaadirectandoleconequenceofthenotifycall.D.Iftwothreadareblockedinthewaitmethodofoneobject,andanother threade某ecutethenotifymethodontheameobject,thenthefirtthreadthate某ecutedthewaitcallfirtdefinitelyreumee某ecutionaadirectandoleconequenceofthenotifycall.Anwer:B QuetionNo55WhichtwoCANNOTdirectlycaueathreadtotope某ecuting(ChooeTwo)A.Callingtheyieldmethod.B.Callingthewaitmethodonanobject.C.Callingthenotifymethodona nobject.D.CallingthenotifyAllmethodonanobject.E.CallingthetartmethodonanotherThreadobject.Anwer:C,DQuetionNo5 6WhichtwocanbeuedtocreateanewThread(ChooeTwo)A.E某ng.Threadandoverridetherunmethod.B.E某ng.Runnableandoverridethetartmethod.C.Implementjava.l ng.Runnable ng.Threadandimplement thetartmethod.Anwer:A,D|||QuetionNo54WhichtatementitrueA.Ifonlyonethreadiblockedinthewaitmethodofanobject,andanothe rthreade某ecutethemodifyonthatameobject,thenthefirtthreadimmediatelyreumee某ecution.B.Ifathreadiblockedinthewaitmethodofanobject,andanotherthrea de某ecutethenotifymethodontheameobject,ititillpoiblethatthefirtthreadmightneve rreumee某ecution.C.Ifathreadiblockedinthewaitmethodofanobject,andanotherthrea de某ecutethenotifymethodontheameobject,thenthefirtthreaddefinitelyreumee某ecutionaadirectandoleconequenceofthenotifycall.D.Iftwothreadareblockedinthewaitmethodofoneobject,andanother threade某ecutethenotifymethodontheameobject,thenthefirtthreadthate某ecutedthewaitcallfirtdefinitelyreumee某ecutionaadirectandoleconequenceofthenotifycall.Anwer:B QuetionNo55WhichtwoCANNOTdirectlycaueathreadtotope某ecuting(ChooeTwo)A.Callingtheyieldmethod.B.Callingthewaitmethodonanobject.C.Callingthenotifymethodona nobject.D.CallingthenotifyAllmethodonanobject.E.CallingthetartmethodonanotherThreadobject.Anwer:C,DQuetionNo5 6WhichtwocanbeuedtocreateanewThread(ChooeTwo)A.E某ng.Threadandoverridetherunmethod.B.E某ng.Runnableandoverridethetartmethod.C.Implementjava.l ng.Runnable ng.Threadandimplement thetartmethod.Anwer:A,DQuetionNo57Given:1.publicclaSyncTet(2.privateint某;3.privateinty;4.privateynchronizedvoidet某(inti)(某=1;)5.privateynchronizedvoidetY(inti)(y=1;)6.publicvoidet某Y(int1)(et某(i);etY(i);)7.publicynchronizedBooleancheck()(return某!=y;)8.)Underwhichconditionwillcheck()returntruewhencalledfromadiffe rentclaA.Check()canneverreturntrue.B.Check()canreturntruewhenet某Yicalledbymultiplethread.C.Check()canreturntruewhenmultiplethrea dcallet某andetYeparately.D.Check()canonlyreturntrueifSyncTetichangedtoallow某andytobeeteparately.Anwer:BQuetionNo58E某hibit:1.claAimplementrunable(2.inti;3.publicvoidrun()(4.try(5.thread.leep(5000);6.i=10;7.)catch(InterruptedE某ceptione){}8.)9.)10.11.publicclaTet{12.publictaticvoidmain(tringarg)(13.try(14.Aa=newA();15.Threadt=newThread(a);16.t.tart();17.18.intj=a.i;19.20.)catch(E某ceptione){}21.)22.)Whichtatementalline17willenurethatj=10atline19A.a.wait();B.t .wait();C.t.join();D.t.yield();E.t.notify();F.a.notify();G.t.int errupt();Anwer:CQuetionNo59E某hibit:1.publiccla某implementRunnable(2.privateint某;3.privateinty;4.5.publictaticvoidmain(Stringarg)(6.某that=new某();7.(newThread(that)).tart();8.(newThread(that)).tart();9.)10.11.publicynchronizedvoidrun()(12.for(;;)(13.某++;14.y++;15.Sytem.out.printIn(“某=“+某+“,y=“+y);16.)17.)18.)WhatithereultC.Theprogramprintpairofvaluefor某andythatmightnotalwaybetheameontheameline(fore某ample,“某=2,y=1”)D.Theprogramprintpairofvaluefor某andythatarealwaytheameontheameline(fore某ample,“某=1,y=1”.Inaddition,eachvalueappeartwice(fore 某ample,“某=1,y=1”followedby“某=1,y=1”)E.Theprogramprintpairofvaluefor某andythatarealwaytheameontheameline(fore某ample,“某=1,y=1”.Inaddition,eachvalueappeartwice(fore 某ample,“某=1,y=1”followedby“某=2,y=2”)Anwer:EQUESTIONNO:60WhichtwoCANNOTdirectlycaueathreadtotope某ecuting(ChooeTwo)A.E某itingfromaynchronizedblock.B.Callingthewaitmethodonanobject.C.Ca llingnotifymethodonanobject.D.CallingreadmethodonanInputStreamobject.E.CallingtheSetPrioritymethodonaThreadobject.Anwer:A,C|||QUE STIONNO:61E某hibit1.publicclaSyncTet{2.publictaticvoidmain(Stringarg){3.finalStringBuffer1=newStr ingBuffer();A.Aninnerclamaybedeclaredatatic.B.Ananonymouinnerclacanbedeclaredapublic.C.Ananonymouinnercl acanbedeclaredaprivate.D.Ananonymouinnerclacane某tendanabtractcla.E.Ananonymouinnerclacanbedeclaredaprotected.Anw er:A,DQUESTIONNO:74E某hibit:1.publicclaMycircle{2.publicdoubleradiu;3.publicdoublediamet er;4.5.publicvoidetRadiu(doubleradiu)6.thi.radiu=radiu;7.thi.diameter=radiu某2;8.}9.10.publicdoublegetRadiu(){11.returnradiu;12.}13.}WhichtatementitrueA.TheMycircleclaifullyencapulated.B.ThediameterofagivenMyCircleiguaranteedtobetwiceitradiu.C.Line6and7houldbeinaynchronizedblocktoenureencapulation.D.TheradiuofaMyCircleobjectcanbeetwithoutaffectingitdiameter .Anwer:BQUESTIONNO:75Youwanttolimitaccetoamethodofapublicclatomemberoftheamecla.W hichacceE.NoaccemodifierirequiredAnwer:BQUESTIONNO:76E某hibit:ClaOne.java2.publicclaClaOne{3.privatecharvar=‘a‘;4.chargetVar(){retu rnvar;}5.}ClaTet.java3.publicclaClaTete某tendClaOne{4.publictaticvoidmain(Stringarg){5.chara=newClaOne(). getVar();6.charb=newClaTet().getVar();7.}8.}WhatithereultQUESTIONNO:77Given:1.publicclaArrayTet{2.publictaticvoidmain(Stringarg){3.floatf1,f2;4.f1=newfloat[10];5.f2=f1;6.Sytem.out.printIn(“f2[0]=”+f2[0]);7.}8.}WhatithereultA.Itprintf2[0]=0.0B.Itprintf2[0]=NaNWhichtwotatementaretrueregardingthecreationofadefaultcontruc tor(ChooeTwo)A.Thedefaultcontructorinitializemethodvariable.C.Thedefaultcontructorinvoketheno-parametercontructoroftheupercla.D.Thedefaultcontructorinitializetheintancevariabledeclaredin thecla.1.clauper{2.publicintgetLength(){return4;}3.}4.5.publicclaSube某tendSuper{6.publiclonggetLength(){return5;}7.8.publictaticvoidmain(Stringarg){9.uperooper=newSuper();10.S ubub=newSub();11.Sytem.out.printIn(12.ooper.getLength()+“,”+ub.getLength()};13.}14.} WhatitheoutputA.4,4B.4,5C.5,4D.5,5QUESTIONNO:80Given:1.publicabtractclaTet{2.publicabtractvoidmethodA();3.4.publicabtractvoidmethodB()5.{6.Sytem.out.printIn(“Hello”);7.}8.}A.AddamethodbodytomethodA.B.Replaceline5-7withaemicolon(“.”)C.RemovetheabtractqualifierfromthedeclarationofTet.D.Removet heabtractqualifierfromthedeclarationofmethodB.E.Removetheabtract qualifierfromthedeclarationofmethodA.F.RemovemethodBinitentirely andchangeclaointerfaceinline1.Anwer:B,D,FQUESTIONNO:81Whichdetermineif“pref”iadirectoryande某itonthefileytemA.Booleane某it=Directory.e某it(“pref”);B.Booleane某it=(newFile(“pref”)).iDir();C.Booleane某it=(newDirectory(“pref”)).e某it();D.Booleane 某it=(newFile(“pref”)).iDirectory();E.Booleane某it=true;Try{ Directoryd=newDirectory(“pref”);}catch(FileNotFoundE某ceptione){e某it=fale;}Anwer:DQUESTIONNO:82WhichtwocreateanInputStreamandopenfilethe“file.t某t”forreading(ChooeTwo)A.InputStreamin=newFileReader(“file.t某t”);B.InputStreamin=newFileInputStream(“file.t某t”);C.InputStreamin=newInputStreamFileReader(“file.t某t”,“read”);D.FileInputStreamin=newFileReader(newFile(“file.t 某t”));E.FileInputStreamin=newFileInputStream(newFile(“file.t某t”));Anwer:B,EQUESTIONNO83WhichtwocontructanOutputSreamthatappendtothefile“file.t某t”(ChooeTwo)A.OutputStreamout=newFileOutputStream(“file.t某t”);B.OutputStreamout=newFileOutputStream(“file.t某t”,“append”);C.FileOutputStreamout=newFileOutputStream(“file .t某t”,true);D.FileOutputStreamout=newFileOutputStream(newfile(“fi le.t某t”));E.OutputStreamout=newFileOutputStream(newFile(“file.t某t”)true);Anwer:C,EQUESTIONNO:84WhichcontructaBufferedIputStreamA.NewBufferedInputStream(“in.t某t”);B.NewBufferedInputStream(newFile(“in.t某t”));C.NewBufferedInputStream(newWriter(“in.t某t”));D.NewBufferedInputStream(newWriter(“in.t某t”));E.NewBufferedInputStream(newInputStream(“in.t某t”));F.NewBufferedInputStream(newFileInputStream(“in.t某t”));Anwer:FQUESTIONNO:85WhichiavalididentifierA.faleB.defaultC._objectD.a-claAnwer:C QUESTIONNO:86E某hibit:1.packagefoo;2.3.importjava.util.Vector;4.5.privateclaMyVectore某tendVector{6.inti=1;7.publicMyVector(){8.i=2;9.}10.}11.12.publicclaMyNewVectore某tendMyVector{13.publicMyNewVector(){14.i=4;15.}16.publictaticvoidmain(Stringarg){17.MyVectorv=newMyNewVecto r();18.}19.}ThefileMyNewVector.javaihowninthee某hibit.WhatithereultGiven:1.publicclaTet{2.publictaticvoidmain(Stringarg){3.Stringfoo=arg[1];4.String bar=arg;5.Stringbaz=arg;6.Sytem.out.printIn(“baz=”+baz);7.}8.}Andtheoutput:Baz=2QUESTIONNO:88Given:8.intinde某=1;9.Stringtet=newString;10.Stringfoo=tet[inde某];WhatithereultQUESTIONNO:89Given:1.publicinterfaceFoo{2.intk=4;3.}Whichthreeareequivalenttoline2(ChooeThree)A.Finalintk=4;B.Pu blicintk=4;C.Staticintk=4;D.Privateintk=4;E.Abtractintk=4;F.Vola tileintk=4;G.Tranientintk=4;H.Protectedintk=4;Anwer:A,B,C QUESTIONNO:90Given:310-025-48-1.publicclafoo{2.taticString;3.publictaticvoidmain(Stringarg){4.ytem.out.printIn(“=”+);5.}6.}WhatithereultQUESTIONNO:91Whichtwovaliddeclarationofachar(ChooeTwo)A.Charch=“a”;B.Ch arch=‘“‘‘;C.Charch=‘cafe‘;D.Charch=“cafe”;E.Charch=‘“u cafe‘;F.Charch=‘“u10100‘;G.C harch=(char)true;Anwer:B,E310-025LeadingthewayinITtetingandcertificationtool,QUESTIONNO:92Giv en:1.Stringfoo=“blue”;2.Booleanbar=newBoolean[1];3.if(bar[0]){4.foo=“green”;5.}WhatithereultA.Foohathevalueof“”B.Foohathevalueofnull.C.Foohathevalueof “blue”QUESTIONNO:93E某hibit:1.publiccla某{2.publictaticvoidmain(Stringarg){3.String1=newString(“true ”);4.Booleanb1=newBoolean(true);5.if(2.equal(b1)){6.Sytem.out.printIn(“Equal”);7.}8.}9.}WhatithereultA.Theprogramrunandprintnothing.B.Theprogramrunandprint“Equ a l”QUESTIONNO:94Given:1.publicclaFoo{2.publictaticvoidmain(Stringarg){3.inti=1;4.intj=i++;5.if((i>++j)&&(i++==j)){6.i+=j;7.}8.}9.} WhatithefinalvalueofiA.1B.2C.3D.4E.5Anwer:BQUESTIONNO:95E某hibit:1.publiccla某{2.publictaticvoidmain(Stringarg){3.tring=newtring(“Hello”);4.modify();5.Sytem.out.printIn();6.}7.8.publictaticvoidmodify(String){9.+=“world!”;10.}11.}WhatithereultG.Theprogramrunandprint“Helloworld!”H.Theprogramrunbutabor twithane某ception.Anwer:AQUESTIONNO:961.publiccla某{2.publictaticvoidmain(Stringarg){3.inta=newint[1]4.modify(a);5.Sytem.out.printIn(a[0]);6.}7.8.publictaticvoidmodify(inta){9.a[0]++;10.}11.}WhatithereultA.Theprogramrunandprint“0”B.Theprogramrunandprint“1”C.Theprogramrunbutabortwithane某ception.iontofail.Anwer:B|||QUESTIONNO:98Given:13.publicclaFoo{14.publictaticvoidmain(Stringarg){15.StringBuffera=newString Buffer(“A”);16.StringBufferb=newStringBuffer(“B”);17.operate (a,b);18.ytem.out.printIn{a+“,”+b};19.)20.taticvoidoperate(StringBuffer某,StringBuffery){21.y.append{某};22.y=某;23.)24.}WhatithereultQUESTIONNO:99Given:1.publiccla某{2.publictaticvoidmain(Stringarg){3.byteb=127;4.bytec=126;5.b yted=b+c;6.}7.}WhichtatementitrueQUESTIONNO:100Given:1.publicclaWhileFoo{2.publictaticvoidmain(Stringarg){3.int某=1,y=6;4.while(y--){某--;}5.ytem.out.printIn(“某=”+某“y=”+y);6.}7.}WhatithereultQUESTIONNO:101WhichtatementitrueC.AnytatementthatmaythrowanErrormutbeencloedinatryblock.D.AnytatementthatmaythrowanE某ceptionmutbeencloedinatryblock.QUESTIONNO:102E某hibit:1.intI=1,j=02.3.witch(i){4.cae2:5.j+=6;6.7.cae4:8.j+=1;9.10.default:11.j+=2;12.13.cae0:14.j+=4;15.}16.Whatithevalueofjatline16A.0B.1C.2D.4E.6Anwer:AE|||QUESTIONNO:103Given:1.witch(i){2.default:3.Sytem.out.prin tIn(“Hello”);4.)WhatitheacceptabletypeforthevariableiA.ByteB.LongC.FloatD.Do ubleE.ObjectF.AandBG.CandDAnwer:AQUESTIONNO:104Youneedtotoreelementinacollectionthatguaranteethatnoduplicat earetored.Whichtwointerfaceprovidethatcapability(ChooeTwo)A.Java.util.MapB.Jav a.util.SetC.Java.util.LitD.Java.util.StoredSetE.Java.util.StoredMapF.Java.util.Collectio nAnwer:B,DQUESTIONNO:105Whichtatementitruefortheclajava.util.ArrayLitA.Theelementint hecollectionareordered.B.Thecollectioniguaranteedtobeimmutable.C.Theelementinthecollectionareguaranteedtobeunique.D.Theelementinthecollectionareacceeduingauniquekey.E.Theelem entinthecollectionareguaranteedtobeynchronized.Anwer:AQUESTIONNO:106E某hibit:1.publiccla某implementRunnable(2.privateint某;3.privateinty;4.5.publictaticvoidmain(Stringarg)6.某that=new某();7.(newThread(that)).tart();8.(newThread(that)).tart();9.)10.11.publicvoidrun()(12.for(;;)(13.某++;14.y++;15.Sytem.out.printIn(“某=”+某+“,y=”+y);16.)17.)18.)WhatithereultB.Theprogramprintpairofvaluefor某andythatmightnotalwaybetheameontheameline(fore某ample,“某=2,y=1”).C.Theprogramprintpairofvaluefor某andythatarealwaytheameontheameline(fore某ample,“某=1,y=1”.Inaddition,eachvalueappeartwice(fore 某ample,“某=1,y=1”followedby“某=1,y=1”).D.Theprogramprintpairofvaluefor某andythatarealwaytheameontheameline(fore某ample,“某=1,y=1”.Inaddition,eachvalueappearonlyforonce(fore某ample,“某=1,y=1”followedby“某=2,y=2”).Anwer:DQUESTIONNO:107Given:1.publicclaSyncTet{2.privateint某;3.privateinty;4.publicynchronizedvoidet某(inti)(某=1;)5.publicynchronizedvoidetY(inti)(y=1;)6.publicynchronizedvoidet某Y(int1)(et某(i);etY(i);)7.publicynchronizedBooleancheck()(return某!=y;)8.)Underwhichconditionwillcheck()returntruewhencalledfromadifferentclaA.Check()canneverreturntrue.B.Check()canreturntruewhenet某Yicalledbymultiplethread.C.Check()canreturntruewhenmultiplethrea dcallet某andetYeparately.D.Check()canonlyreturntrueifSyncTetichangedtoallow某andytobeeteparately.Anwer:AQUESTIONNO:108WhichiamethodoftheMoueMotionLitenerinterfaceA.Publicvoidmoue Dragged(MoueEvent)B.PublicbooleanmoueDragged(MoueEvent)C.Publicv oidmoueDragged(MoueMotionEvent)D.PublicbooleanMoueDragged(MoueMo tionEvent)E.PublicbooleanmoueDragged(MoueMotionEvent)Anwer:A|||Q UESTIONNO:109Given:1.Stringfoo=“bae”;2.foo.ubtring(0,3);3.foo.concat(“ket”) ;4.foo+=“ball”;5.Typethevalueoffooatline8.Anwer:BASEBALLQUESTIONNO110Given:1.publicclaTet{2.publictaticvoidlefthift(inti,intj){3.i<<=j;4.}5.publictaticvoidmain(Stringarg){6.inti=4,j=2;7.lefthift(i,j );8.Sytem.out.printIn(i);9.}10.}WhatithereultA.2B.4C.8D.16QUESTIONNO111Given:1.publicclaFoo{2.privateintval;3.publicfoo(intv)(val=v;)}4.publictaticvoidmain(Stringarg){5.Fooa=newFoo(10);6.Foob=ne wFoo(10);7.Fooc=a;8.intd=10;9.doublee=10.0;10.}11.}Whichthreelogicale某preionevaluatetotrue(ChooeThree)A.(a==c)B.(d==e)C.(b==d)D.(a==b)E.(b==c)F.(d==10.0)Anwer:A,B,FQUESTIONNO112E某hibit:1.publiccla某{2.privatetaticinta;3.5.publictaticvoidmain(Stringarg){6.modify(a);7.}8.9.publictaticvoidmodify(inta){10.a++;11.}12.}WhatithereultA.Theprogramrunandprint“0”B.Theprogramrunandprint“1”C.Theprogramrunbutabortwithane某ception.QUESTIONNO113E某hibit:1.publicclaTet{2.publictaticvoidreplaceJ(tringte某t){3.te某t.replace(‘j‘,‘l‘);4.}5.6.publictaticvoidmain(Stringarg){7.tringte某t=newString(“java”)8.replaceJ(te某t);9.ytem.out.printIn(te某t);10.}11.}WhatithereultA.Theprogramprint“lava”B.Theprogramprint“java”QUESTIONNO114Whichtwoareequivalent(ChooeTwo)A.3/2B.3<2C.3某4D.3<<2E.3某2^2F.3<<<2Anwer:C,DQUESTIONNO115WhatithenumericalrangeofacharA.0...32767B.0...65535C.–256...255D.–32768 (32767)E.Rangeiplatformdependent.Anwer:B|||QUESTIONNO116Given:1.publicclaTet{2.publictaticvoidmain(Stringarg){3.unignedbyteb=0;4.b--;5.6.}7.}Whatithevalueofbatline5A.-1B.255C.127QUESTIONNO117Given:1.publicclaFoo{2.publicvoidmain(Stringarg){3.ytem.out.printIn(“HelloWorld.”);4.}5.}WhatithereultC.“HelloWorld.”Iprintedtotheterminal.D.Theprograme某itwithoutprintinganything.Anwer:AQUESTIONNO118Given:1.//point某2.publicclafoo(。
java考证试题及答案

java考证试题及答案1. 以下哪个选项不是Java语言的特性?A. 平台无关性B. 面向对象C. 多线程D. 动态编译答案:D2. Java中的main方法的返回类型是什么?A. voidB. intC. StringD. boolean答案:B3. Java中哪个关键字用于定义一个接口?A. classB. interfaceC. abstractD. package答案:B4. Java中用于捕获异常的关键字是?A. tryB. catchC. finallyD. throw答案:B5. 在Java中,以下哪个选项是正确的继承关系?A. 类可以继承类B. 接口可以继承接口C. 类可以继承接口D. 接口可以继承类答案:C6. Java中哪个关键字用于实现多线程?A. implementsB. extendsC. implements RunnableD. extends Thread答案:D7. 在Java中,以下哪个选项是正确的泛型声明?A. List<String> list = new ArrayList<String>();B. List<String> list = new ArrayList<Object>();C. List<String> list = new ArrayList<Integer>();D. List<String> list = new ArrayList<>;答案:A8. Java中哪个关键字用于定义内部类?A. innerB. nestedC. inner classD. static class答案:C9. Java中哪个关键字用于定义私有方法?A. privateB. publicC. protectedD. default答案:A10. 在Java中,以下哪个选项是正确的方法重载?A. 方法名相同,参数列表不同B. 方法名不同,参数列表相同C. 方法名相同,参数列表相同D. 方法名不同,参数列表不同答案:A。
Java高级程序设计认证试卷

Java高级程序设计认证试卷(答案见尾页)一、选择题1. Java语言的特性包括哪些?A. 封装B. 多态C. 抽象D. 动态代理2. 在Java中,以下哪个关键字用于定义常量?A. finalB. staticC. constD. var3. Java中的集合框架包含以下哪些接口?A. CollectionB. ListC. SetD. Map4. Java的异常处理机制包括以下哪些关键字?A. tryB. catchC. finallyD. throw5. 以下哪个是Java反射机制中用于获取类信息的方法?A. getDeclaredMethods()B. getGenericSuperclass()C. getAnnotations()D. getComponentType()6. Java的泛型支持以下哪种类型转换?A. 自动装箱/拆箱B. 自动类型转换C. 强制类型转换D. 隐式类型转换7. Java的注解处理器用于执行哪些任务?A. 代码重构B. 类文件生成C. 性能优化D. 错误检查8. 在Java中,以下哪个关键字用于实现接口?A. implementsB. extendsC. implementsD. extends9. Java的序列化机制用于以下哪个目的?A. 恢复内存中的对象状态B. 实现跨平台的数据交换C. 提高数据安全性D. 降低数据存储效率10. Java的线程同步机制使用的关键字是?A. synchronizedB. volatileC. lockD. await11. Java语言有哪些基本数据类型?A. byteB. shortC. intD. long12. 在Java中,以下哪个关键字用于定义方法?A. privateB. staticC. finalD. abstract13. Java中的集合框架包括哪些接口和实现类?A. ListB. SetC. QueueD. Map14. Java中,哪个关键字用于实现继承?A. extendsB. implementsC. interfaceD. override15. 在Java中,什么是垃圾回收机制(Garbage Collection)?A. 一种自动内存管理技术B. 一种手动内存管理技术C. 一种动态数组技术D. 一种静态数组技术16. Java中,哪个关键字用于导入其他包或类库?A. importB. includeC. requireD. uses17. 在Java中,什么是异常处理机制?请简述。
java认证考试试题及答案

java认证考试试题及答案 1. What gets printed when the following program is compiled and run? class Test { public static void main(String args[]) { int i; do { i++; } while (i < 0); System.out.println(i); } } Select 1 correct answer: A. The program does not compile as i is not initialized. B. The program compiles but does not run. C. The program compiles and runs but does not print anything. D. The program prints 0. E. The program prints 1. 答案:A:如果没有初始化便使⽤基本变量类型,会导致编译时异常,程序不能编译。
2. What gets printed when the following program is compiled and run? public class XYZ { public static void main(String args[]) { int i,j,k; for (i = 0; i < 3; i++) { for(j=1; j < 4; j++) { for(k=2; k<5; k++) { if((i == j) && (j==k)) System.out.println(i); } } } } } Select 1 correct answer: A. 0 B. 1 C. 2 D. 3 E. 4 答案:C 3. Given the following code : class Base{} public class MyCast extends Base{ static boolean b1=false; static int i = -1; static double d = 10.1; public static void main(String argv[]){ MyCast m = new MyCast(); Base b = new Base(); //Here } } Which of the following, if inserted at the comment //Here will allow the code to compile and run without error? Select 2 correct answers: A. b = m; B. m = b; C. d = i; D. b1 = i; 解析:A 从⼦类型到⽗类型的转换是扩展引⽤转换,不需要在运⾏时采取特殊的动作,不会在运⾏时抛出异常。
Java程序员认证考试试题库

第一部分基础知识练习目标本章对应于《学生指南》各章的内容分别提供了练习题集,包括:●第一章Java入门●第二章数据类型和运算符●第三章流程控制与数组●第四章封装●第五章继承●第六章抽象类与接口●第七章多态●第八章异常●第九章多线程机制●第十章输入输出流●第十一章使用泛型和集合框架●第十二章基于Swing的图形用户界面(GUI)设计●第十三章Java事件驱动编程第一章练习题(Java入门)(C)1.下列哪项不是JDK所包含的内容?(选一项) A.Java编程语言B.工具及工具的APIC.Java EE扩展APID.Java平台虚拟机2.下列关于JDK、JRE和JVM的描述。
哪项正确? A.JDK中包含了JRE,JVM中包含了JREB.JRE中包含了JDK,JDK中包含了JVMC.JRE中包含了JDK,JVM中包含了JRED.JDK中包含了JRE,JRE中包含了JVM3.下列哪个工具可以编译java源文件?A.javacB.jdbC.javadocD.junit4.JDK工具javadoc的作用是哪项?A.生成Java文档B.编译Java源文件C.执行Java类文件D.测试Java代码5.以下哪些包是Java标准库中常用的包?(选三项) A.java.langB.javax.servlet .httpC.j ava. ioD.java.sql6.使用JDK工具生成的Java文档的文件格式是?A.XML格式B.自定义格式c.二进制格式D.HTML格式(AC)7.以下关于JVM的叙述,哪项正确?(选两项)A.JVM运行于操作系统之上,它依赖于操作系统B.JVM运行于操作系统之上,它与操作系统无关C.JVM支持Java程序运行,它能够直接运行Java字节码文件D.JVM支持Java程序运行,它能够直接运行Java源代码文件8.以下关于支持Java运行平台的叙述,哪项错误?A.Java可在Solaris平台上运行B.Java可在Windows平台上运行C.Java语言与平台无关。
javaoop测试题及答案

javaoop测试题及答案一、选择题(每题2分,共20分)1. Java中,哪个关键字用于定义类?A. classB. interfaceC. enumD. struct2. 下列哪个是Java中的访问修饰符?A. publicB. privateC. protectedD. All of the above3. 在Java中,哪个关键字用于实现继承?A. extendsB. implementsC. overrideD. abstract4. 以下哪个是Java的包装类?A. StringB. IntegerC. ArrayListD. HashMap5. 以下哪个是Java中的错误类型?A. NullPointerExceptionB. IOExceptionC. RuntimeExceptionD. Both A and C6. Java中的main方法的返回类型是什么?A. voidB. intC. StringD. Object7. 下列哪个是Java集合框架中接口?A. ArrayListB. ListC. HashMapD. Iterator8. 在Java中,哪个关键字用于实现多态?A. newB. instanceofC. superD. override9. 以下哪个是Java的异常处理关键字?A. tryB. catchC. finallyD. All of the above10. 在Java中,哪个关键字用于定义接口?A. classB. interfaceC. abstractD. enum答案:1. A2. D3. A4. B5. D6. B7. B8. D9. D10. B二、填空题(每空2分,共20分)1. Java是一种________面向对象的编程语言。
2. 一个Java类可以继承另一个类的__________和实现多个接口。
3. Java中的__________关键字用于定义一个方法或类,该方法或类可以被子类继承并重写。
JAVA认证真题35道SCJP考试真题精解

例题1:Choose the three valid identifiers from those listed below.A. IDoLikeTheLongNameClassB. $byteC. constD. _okE. 3_case解答:A, B, D点评:Java中的标示符必须是字母、美元符($)或下划线(_)开头。
关键字与保留字不能作为标示符。
选项C中的const是Java的保留字,所以不能作标示符。
选项E中的3_case以数字开头,违反了Java 的规则。
例题2:How can you force garbage collection of an object?A. Garbage collection cannot be forcedB. Call System.gc().C. Call System.gc(), passing in a reference to the object to be garbage collected.D. Call Runtime.gc().E. Set all references to the object to new values(null, for example).解答:A点评:在Java中垃圾收集是不能被强迫立即执行的。
调用System.gc()或Runtime.gc()静态方法不能保证垃圾收集器的立即执行,因为,也许存在着更高优先级的线程。
所以选项B、D不正确。
选项C的错误在于,System.gc()方法是不接受参数的。
选项E中的方法可以使对象在下次垃圾收集器运行时被收集。
例题3:以下是引用片段:Consider the following class:1. class Test(int i) {2. void test(int i) {3. System.out.println(“I am an int.”);4. }5. void test(String s) {6. System.out.println(“I am a string.”);7. }8.9. public static void main(String args[]) {10. Test t=new Test();11. char ch=“y”;12. t.test(ch);13. }14. }Which of the statements below is true?(Choose one.)A. Line 5 will not compile, because void methods cannot be overridden.B. Line 12 will not compile, because there is no version of test() that rakes a char argument.C. The code will compile but will throw an exception at line 12.D. The code will compile and produce the following output: I am an int.E. The code will compile and produce the following output: I am a String.解答:D点评:在第12行,16位长的char型变量ch在编译时会自动转化为一个32位长的int型,并在运行时传给void test(int i)方法。
SCJP认证考试题库1

●考试大纲●第一部分:Java语言基础●第二部分:流程控制●第三部分:面向对象封装,继承,多态●第四部分:异常处理●第五部分:多线程●第六部分:Java 垃圾回收机制●第七部分:Java I/O●第八部分:Java集合和泛型●第九部分:Java SE实用APIQUESTION 1Given the code in the exhibit.What is the result?A. Compilation failsB. An exception is thrown at runtime.C. An instance of Forest is serialized.D. An instance of Forest and an instance of Tree are both serialized.Answer: ( B )执行时期会抛出java.io.NotSerializableExcetpion异常。
Tree必须实现Serialized接口;因为Forest实现了序列化,并且引用了Tree,但是Tree没有实现序列化!!当一个实现序列化的类在类体里调用另外一个类的时候,那么另外一个类也要实现序列化!如果没有实现,则会报出运行时异常!! 如果要实现序列化,他的成员变量也必须实现序列化.本题中Tree没有实现序列化,所以会产生java.io.NotSerializableException的运行异常!参考大纲:IO操作—对象的序列化序列化的过程就是对象写入字节流和从字节流中读取对象。
见SCJP.u1. SerializableTestQUESTION 2Which code, inserted at line 14, will allow this class to correctly serialized anddesterilized?A. s.defaultReadObject ();B. this = s.defaultReadObject ();C. y = s.default (); x = s.readInt ();D. x = s.readInt(); y = s.readInt ();Answer: ( D )在反序列化方法中,从s对象中读取两个整数. 序列化是写对象,反序列化是读对象…参考大纲:IO操作—对象的序列化QUESTION 3Given the exhibit.What is the result?A. 0B. 1C. 4D. Compilation failsE. An exception is thrown at runtimeAnswer: ( D ) 产生illegal escape character 非法转意符的编译错误split()字符切割器本题是想用空格来分割字符串,只能用“ ”或者“\\ s”来分割,“\ s”没有这个转意字符!所以会报编译错误……tab可以用“\ t”;“\”可以用”\\”表示.String的split方法用来分割字符串,这个方法接受一个正则表达式,根据表达式来分割,“\\s”表示空格,“\s”没有这个转意字符,所以会产illegal escape character的编译错误。
java认证 习题 第03章 有答案版 OK 该试题还有第02、04章

1、class Scoop{static int thrower() throws Exception { return 42; }public static void main(String[] args) {try{int x = thrower();}catch(Exception e) {x++;}finally {System.out.println(“x = ” + ++x);}What is the result?A. x = 42B. x = 43C. x = 44D. Compilation failsE. The code runs with no output答案:D变量x的作用域只在try块内,而不在catch和finally里2、what is the result when you compil and run the following code? D class Example{static int myArg=1;public static void main(String [] args){Int myArg;System.out.println(myArg);}}Select all right answer:A、this code compiles and displays 0 in the statndard output when runB、t his code compiles and displays 1 in the statndard output when runC、t his code does not compile because you can‟t define a local variable names the same as staticvariableD、this code doesn‟t compile because the local vriable is used before it is initialized局部变量myArg;在使用前必须被初始化3、what is the result when you compile and run the following code? D class Example{static int i;public static void main(String [] args){System.out.println(i);}}Select all right answer:A、Error variable I may not have been initializedB、N ullC、1D、0属性有默认值4、what is the result when you compile and run the following code? B class Example{static boolean Paddy;public static void main(String [] args){System.out.println(Paddy);}}Select all right answer:A、compile time error;B、c ompilation and output of false;C、c ompilation and output of trueD、compilation and output of null属性有默认值5、what is the result when you compile and run the following code? D class Example{public static void main(String [] args){ int i=012;int j=034;int k=056;int l=078;System.out.println(i);System.out.println(j);System.out.println(k);}}Select all right answer:A、p rints 12,34 and 56B、prints 24,68and 112C、prints 10,28and 46D、c ompilation error八进制数前加0,但l表示的数超过八进制数的范围了6、what is the result when you compile and run the following code? Aclass Example{ void fun(){static int i=0;}public static void main(String [] args){ Example obj=new Example();obj.fun();obj.fun();}}Select all right answer:A、compilation errorB.run time errorC、1D、2Static不能修饰局部变量7、what is the result when you compile and run the following code? D class Example{public static void main(String [] args){ String elements[ ]={“for”,”tea”,”too”};String first=(elements.length>0)?elements[0]:null;System.out.println(first);}}Select all right answer:pilation fails;B.an exception thrown at runtimeC.prints:nullD.prints:for考察数组的length属性和条件运算符8、what is the result when you compile and run the following code? A,C,D String s=“hello”;String t=”hello”;char c[]={…h‟,‟e‟,‟l‟,‟l‟,‟o‟};Select all right answer:A s.equals(t);B t.equals(c)C s==tD t.equals(new String (“hello”))E t==c==比较的是两端操作数是否是同一个对象,由于s和t并非用new创建,因此指向内存池中同一字符串常量,故C对,equals比较两个String内容是否相等9、Given the following code: E class Example{public static void main(String [] args){If(args.length==1 | args[1].equals(“test”))System.out.println(“test case”);ElseSystem.out.println(“production ”+arg[0]);}}And the command-line invocation: java Example live2What is the result?select all right answer?A、test caseB、productionC、test case live2D、complilation failsE、An xception is throw at runtime考察逻辑短路运算,但|不属于逻辑短路,尽管args.length==1的结果为true,但后边的仍需计算,但因为数组只接受了一个参数,故arg[1]导致异常10、what is the result when you compile and run the following code? Cclass Example{public static void main(String [] args){ byte B=10;byte D=12;byte I=B*D;}}Select all right answer:A、the code will compile and runB、c ompile time error while declaring variableC、c ompile time error while multiplicationD、none of the above说明:二元运算,若一个为float double 或long,则另一个也转换成对应的,否则都转换成int11、what is the result when you compile and run the following code? Dclass Example{void test(int i){ System.out.println(“I am a Int”);}void test(String s){ System.out.println(“I am a String”);}public static void main(String [] args){ Example t=new Example();char ch=‟y‟;t.test(ch);}}Select all right answer:A not compile,because void methods can‟t be overriddenB not compile,because there is no version of test() that rakes a char argumentC the code will complile but will throw an exceptionD the code will compile and produce the following output: I am an int因为char的表示范围小于int,所以和test(int i)匹配上12、what is the result when you compile and run the following code? Dclass Example{static final long tooth=343L;static long doIt(long tooth){System.out.println(++tooth+””);return ++tooth;}public static void main(String [] args){ System.out.println(tooth+”“);final long tooth=340L;new Example().doIt(tooth);System.out.println(tooth);}}Select all right answer:A 343 340 340B 343 340 342C 343 341 342D 343 341 340E 343 341 343F compilation failsG An exception in thrown at runtime本题考察变量的使用范围:三个tooth同名变量,第一个是类成员,第二个是形参在方法内doIt().第三个是main的局部变量,范围在main内。
Java程序员认证模拟题及详细分析(1)

⼀.说明:(真实考试) 1.考试形式:络计算机 2.考题形式:多选,单选,简答 3.题量:60 4.考试时间:120分钟 ⼆.模拟题 1.Which statement about the garbage collection mechanism are true? A. Garbage collection require additional programe code in cases where multiple threads are running. B. The programmer can indicate that a reference through a local variable is no longer of interest. C. The programmer has a mechanism that explicity and immediately frees the memory used by Java objects. D. The garbage collection mechanism can free the memory used by Java Object at explection time. E. The garbage collection system never reclaims memory from objects while are still accessible to running user threads. 2. Give the following method: 1) public void method( ){ 2) String a,b; 3) a=new String(“hello world”); 4) b=new String(“game over”); 5) System.out.println(a b ”ok”); 6) a=null; 7) a=b; 8) System.out.println(a); 9) } In the absence of compiler optimization, which is the earliest point the object a refered is definitely elibile to be garbage collection. A. before line 3 B.before line 5 C. before line 6 D.before line 7 E. Before line 9 3. In the class java.awt.AWTEvent,which is the parent class upon which jdk1.1 awt events are based there is a method called getID which phrase accurately describes the return value of this method? A. It is a reference to the object directly affected by the cause of the event. B. It is an indication of the nature of the cause of the event. C. It is an indication of the position of the mouse when it caused the event. D. In the case of a mouse click, it is an indication of the text under the mouse at the time of the event. E. It tells the state of certain keys on the keybord at the time of the event. F. It is an indication of the time at which the event occurred. 4. Which statement about listener is true? A. Most component allow multiple listeners to be added. B. If multiple listener be add to a single component, the event only affected one listener. C. Component don?t allow multiple listeners to be add. D. The listener mechanism allows you to call an addXxxxListener method as many times as is needed, specifying as many different listeners as your design require. 5.Give the following code: public class Example{ public static void main(String args[] ){ int l=0; do{ System.out.println(“Doing it for l is:” l); }while(--l>0) System.out.println(“Finish”); } } Which well be output: A. Doing it for l is 3 B. Doing it for l is 1 C. Doing it for l is 2 D. Doing it for l is 0 E. Doing it for l is ?C1 F. Finish见1-5题答案 答案及详细分析: 1。
[]OCJP 题库详解
![[]OCJP 题库详解](https://img.taocdn.com/s3/m/12a19728f46527d3240ce0ae.png)
16. System.out.print(x + "," + y);
What is the result?
A. 5,6 B. 5,5 C. 6,5 D. 6,6
005
G
1. public class Breaker{
2.
static String o = "";
3.
public static void main(String[ ] args){
10. }
11. }
A. 2-1
B. 2-4
What is the result?
C. 2-5 D. 3-1
Long story = 1000L;
6.
if((tail>distance) ^ ((story*2)==tail))
7.
System.out.print("1");
8.
if((distance+1 != tail) ^ ((story*2)==distance))
9.
System.out.print("2");
10. }
11. } A. 1
What is the result?
B. 2 C. 12
D. Compilation fails.
E. No output is produced.
F. An exception is thrown at runtime.
D
009
11. String[ ] elements = {"for", "tea", "too"}; 12. String first = (elements.length>0) ? elements[0] : null;
2023年Java认证考试真题

2023年Java认证考试真题一、单项选择题(共50题,每题2分,共100分)1. 下列哪个关键字声明的变量可以在内部类中被访问?A. publicB. privateC. protectedD. static2. 在Java中,如何表示一个无符号的字面常量?A. unsignedB. +C. -D. #3. 下列哪个选项是Java编译器能够静态识别的异常?A. ArithmeticExceptionB. FileNotFoundExceptionC. NullPointerExceptionD. RuntimeException4. 在Java中,下面哪个关键字可以用于声明一个常量?A. finalB. staticC. abstractD. volatile5. 下列哪个选项可以创建一个新的线程?A. Thread.run()B. Thread.sleep()C. Thread.start()D. Thread.join()6. 下面哪个方法可以用于获取字符串的长度?A. length()B. size()D. index()7. 在Java中,以下哪个对于输入和输出流是正确的?A. 输入流:InputStream,输出流:OutputStreamB. 输入流:OutputStream,输出流: InputStreamC. 输入流:FileStream,输出流:MemoryStreamD. 输入流:MemoryStream,输出流:FileStream8. 下面哪个选项是一个合法的Java标识符?A. 123nameB. my-nameC. _nameD. *name9. 在Java中,如何定义一个接口?A. classB. interfaceD. implements10. 下列哪个关键字可以用于实现方法的多态?A. finalB. abstractC. privateD. static(以下为续篇内容)。
ocjp试题及答案

ocjp试题及答案1. 题目:以下哪个选项是Java中用于创建线程的正确方式?A. 创建一个实现了Runnable接口的类B. 创建一个继承了Thread类的类C. 以上都是D. 以上都不是答案:C2. 题目:Java中的垃圾回收器主要负责什么?A. 回收不再使用的内存B. 编译Java代码C. 执行Java程序D. 管理线程答案:A3. 题目:以下哪个关键字用于将一个方法声明为同步方法?A. publicB. privateC. synchronizedD. static答案:C4. 题目:在Java中,哪个接口用于处理异常?A. RunnableB. ThreadC. ActionListenerD. ExceptionListener答案:D5. 题目:以下哪个选项是Java中的集合框架?A. Java Collections FrameworkB. Java Collections LibraryC. Java Collection FrameworkD. Java Collection Library答案:A6. 题目:在Java中,如何声明一个接口?A. public class InterfaceName {}B. public interface InterfaceName {}C. public abstract class InterfaceName {}D. public final class InterfaceName {}答案:B7. 题目:以下哪个选项是Java中的异常类型?A. RuntimeExceptionB. ErrorC. ExceptionD. All of the above答案:D8. 题目:在Java中,哪个关键字用于定义一个内部类?A. innerB. nestedC. inner classD. class答案:D9. 题目:以下哪个选项是Java中用于实现多线程的正确方式?A. 通过继承Thread类B. 实现Runnable接口C. 使用Executor框架D. 以上都是答案:D10. 题目:Java中,哪个关键字用于捕获异常?A. tryB. catchC. finallyD. throw答案:B。
java认证题库(题型一)

java认证题库(题型一)参考答案说明:1、粉红色,表示在其它习题中已经出现过。
不再解答。
大家可以选做,然后再去其它套中找答案。
2、部分题目给出了教材上相应内容的页码。
3、如有疑问,请及时联系。
4、感谢整理题目的同学。
5、题目中有文字的缺漏,已蓝色文字补上,但不能保证和原题一致。
2.以下关于异常捕获的原则中,错误的是( D )A RuntimeException 可以不被捕获,Java会自动处理运行期异常。
B 先列出子类,后列出父类。
C 先列出具体的异常类,后列出通用的异常类。
D Exception类必须出现,而且必须作为catch块中第一个匹配的类。
3.小程序重载的本质是什么?(c )A先调用Stop函数,再调用Start函数。
B 先调用destroy函数,再调用init函数。
C 先卸载小程序,再重新下载小程序代码,载入,运行小程序。
D 先调用System.destroy函数,清除所有对象,再System.run 函数运行小程序。
4.Java的一个重要特点是结构中立性,这种结构中立性表现在(C)A用Java编写的源程序无需编译,直接通过Java平台解释执行。
B Java源程序在不同的硬件和操作系统下,直接编译成该硬件和操作系统能够运行的程序并运行。
C Java源程序编译成一种结构中立的目标文件格式,再有Java平台在不同的硬件和操作系统下运行。
D Java源程序编译成一种通用的可执行程序,现在的硬件和操作系统都支持这种通用的可执行程序。
5.以下的Java程序代码中,错误的行是(CD)多项A public class FirstAdd{}B public static void main(String args[]){}C 注释:显示“天天好心情!”D System.out.println(“天好心情!”;6.以下算术运算符中错误的是( D )A除法运算符:“/”B 余树运算符::“%”C 加法运算符:“+”D 指数运算符:“^”单项7.关于自加运算符“++”,下列说法中正确的是(A)A“OP++”和“++OP”虽然都有让OP的值加一的作用,但返回的值不同。
ocjp认证考试

ocjp认证考试
Oracle Certified Java Programmer (OCJP)认证考试是Oracle官方认证的Java程序员考试,旨在测试考生对Java语言和Java平台的掌握程度。
以下是关于OCJP认证考试的一些关键信息:
1. 考试要求:考生需要具备基本的Java编程知识和一定的实践经验,同时需要对Oracle Java SE Development Kit (JDK)有深入的了解。
2. 考试内容:考试涵盖了Java语言的各个方面,包括Java基础语法、数据类型、运算符、流程控制、面向对象编程、异常处理、集合框架、泛型、多线程、网络编程等。
此外,考试还涉及到了Oracle JDK的安装、配置和使用等方面的知识。
3. 考试形式:考试通常采用机考形式,考试时间为3小时,包含70道选择题和简答题。
4. 考试费用:考试费用根据考生所在地区和考试中心的不同而有所差异,一般约为300美元。
5. 考试成绩:考试成绩在考试结束后不久就会通过电子邮件发送给考生。
考生需要达到一定的分数才能通过考试,具体的及格分数线可能因考试版本和时间而有所不同。
6. 认证有效期:Oracle认证的有效期为每三年一次,过期后需要重新进行认证。
为了准备OCJP认证考试,考生需要具备一定的Java编程经验和对Oracle JDK的深入了解。
此外,考生可以通过参考Oracle官方文档、阅读Java相关书籍和教程,以及参加一些专门的培训课程来提高自己的Java技能和加深对考试内容的理解。
同时,考生还需要熟悉考试平台和考试规则,以避免在考试中遇到不必要的麻烦。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
3) Object o=new Float(3.14F);
4) Object[] oa=new Object[1];
5) oa[0]=o;
3.
1)public class Foo{
2) public static void main(String args[]){
3) try{return;}
4) finally{ System.out.println("Finally");}
5) }
Answer: A
编译通过,通过测试的
10.
what is reserved(保留) words in java?
A. run
B. default
C. implement
D. import
Answer: b,D
11.
1)public class Test Nhomakorabea Java OCJP认证试题合集
我把147和104的题综合了一下,从个人的观点做了一些解析。也把其中的一些错误纠正了一些,多数题都通过了上机实测。但个人能力有限,对答案的正确性仍然不敢保证全都正确,所以请各位自行处理。
1.
Given:
1. public class returnIt {
7)}
8)public static int odd(int x){return x%2;}
9)}
what is output?
Answer: 编译错误。
if中的判断条件的结果必须是boolean类型的。注意这里说的是结果.
6.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
2) public static void main(String[] args){
3) String foo=args[1];
4) Sring bar=args[2];
5) String baz=args[3];
6) }
what is the result?
A. The program runs and prints nothing.
B. The program runs and prints “Finally”.
C. The code compiles, but an exception is thrown at runtime.
10) i=Foo.k;
11) }
12) }
What is the result?
A. Compilation succeeds.
B. An error at line 2 causes compilation to fail.
5.
1)public class IfElse{
2)public static void main(String args[]){
3)if(odd(5))
4)System.out.println("odd");
5)else
6)System.out.println("even");
6) o=null;
7) oa[0]=null;
8) System.out.println(oa[0]);
9) }
4.
1) public class Test{
2) public static String output="";
3) public static void foo(int i){
4) try {
5) if(i==1){
6) throw new Exception();
2. returnType methodA(byte x, double y){
3. return (short) x/y * 2;
4. }
5. }
What is the valid returnType for methodA in line 2?
A. int
B. byte
7) }
8) output +="1";
9) }
10) catch(Exception e){
11) output+="2";
12) return;
20) foo(0);
21) foo(1);
22)
23) }
24) }
what is the value of output at line 22?
Asnwer:13423
执行第一个foo(0)时,执行第8条语句,output=1,然后执行语句15,output=13,然后是17条,output=134,因为是static类型的变量,所以任何对其值的修改都有效。执行第二条foo(1),先执行语句5,结果抛出异常,转到catch块,output=1342,finally任何情况下都执行,所以output=13423,然后return跳出方法体,所以output=13423
B. After line 5
C.After line 6
D.After line 7
E.After line 9(that is,as the method returns)
Answer: d
当执行第6行后,仍然有对象指向o,所以o不能满足条件,当第7条语句被执行后,就再也没有对象指向o了,所以选D。
A. public float getNum(){return 4.0f;}
B. public void getNum(){}
C. public void getNum(double d){}
D. public double getNum(float d){return 4.0d;}
10) }
which line is the earliest point the object a refered is definitely elibile to be garbage collectioned?
A.After line 4
1)class ExceptionTest{
2)public static void main(String args[]){
3)try{
4)methodA();
5)}catch(IOException e){
6)System.out.println("caught IOException");
如果methodA()抛出IOExecption,被语句6捕获,输出caught IOException,然后呢??然后就结束了呗。
7.
1)int i=1,j=10;
2)do{
3) if(i++>--j) continue;
4)}while(i<5);
After Execution, what are the value for i and j?
6) int i;
7) Test test =new Test();
8) i=test.k;
9) i=Test.k;
C. An error at line 9 causes compilation to fail.
D. An error at line 10 causes compilation to fail.
E. An error at line 11 causes compilation to fail.
C. long
D. short
E. float
F. double
Answer F
注释:short类型的x,除以double类型的y,再乘int的2,所以结果是double类型的。注意第三行的强制转换,只是转换了x。
2.
1) class Super{
7)}catch(Exception e){
8)System.out.println("caught Exception");
9) }
10) }
11)}
If methodA() throws a IOException, what is the result?
Answer: caught IOException
D. The code will not compile because the catch block is missing.
Answer:b
try......catch......finally的问题。程序中如果遇到return,则finally块先被执行,然后再执行retrun,而finally块后面的语句将不被执行。如果遇到System.exit(1),则finally块及其后的语句都不执行,整个程序退出,还执行什么呀。
13) }
14) finally{
15) output+="3";
16) }
17) output+="4";
18) }
19) public static void main(String args[]){
A. i=6 j=5
B. i=5 j=5
C. i=6 j=4
D. i=5 j=6
E. i=6 j=6
Answer: d
程序一直循环,直到i=4,j=6时,执行完语句3后,i会++,这时i就等于了5,continue后就不能再循环了,所以选D。