java认证之SCJP考试试题及答案讲解_第1页
java认证之SCJP考试试题及答案讲解_第2页
java认证之SCJP考试试题及答案讲解_第3页
java认证之SCJP考试试题及答案讲解_第4页
java认证之SCJP考试试题及答案讲解_第5页
已阅读5页,还剩53页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Question1Given:11.publicinterfaceStatus{12./*insertcodehere*/intMY_VALUE=10;13.}Whichthreearevalidonline12?(Choosethree.)A.finalB.staticC.nativeD.publicE.privateF.abstractG.protectedABDQuestion2Given:10.publicclassBar{11.staticvoidfoo(int...x){12.//insertcodehere13.}14.}Whichtwocodefragments,insertedindependentlyatline12,willallowtheclasstocompile?(Choosetwo.)A.foreach(x)System.out.println(z);B.for(intz:x)System.out.println(z);C.while(x.hasNext())System.out.println(x.next());D.for(inti=0;i<x.length;i++)System.out.println(x[i]);BDQuestion3Given:11.publicclassTest{12.publicstaticvoidmain(String[]args){13.intx=5;14.booleanb1=true;15.booleanb2=false;16.17.if((x==4)&&!b2)18.System.out.print("l");19.System.out.print("2");20.if((b2=true)&&b1)21.System.out.print("3");22.}23.}Whatistheresult?A.2B.3C.12D.23E.123F.Compilationfails.G.Auexceptionalisthrownatruntime.DQuestion4Given:11.String[]elements={"for","tea","too"};12.Stringfirst=(elements.length>0)?elements[0]:null;Whatistheresult?A.Compilationfails.B.Anexceptionisthrownatruntime.C.Thevariablefirstissettonull.D.Thevariablefirstissettoelements[0].DQuestion5Given:10.interfaceFoo{}11.classAlphaimplementsFoo{}12.classBetaextendsAlpha{}13.classDeltaextendsBeta{14.publicstaticvoidmain(String[]args){15.Betax=newBeta();16.//insertcodehere17.}18.}Whichcode,insertedatline16,willcauseajava.lang.ClassCastException?A.Alphaa=x;隐式向上造型B.Foof=(Delta)x;beta不能转换为deltaC.Foof=(Alpha)x;D.Betab=(Beta)(Alpha)x;BQuestion6Given:11.classCup{}12.classPoisonCupextendsCup{}21.publicvoidtakeCup(Cupc){22.if(cinstanceofPoisonCup){23.System.out.println("Inconceivable!");24.}elseif(cinstanceofCup){25.System.out.println("Dizzyingintellect!");26.}else{27.System.exit(0);28.}29.}Andtheexecutionofthestatements:Cupcup=newPoisonCup();takeCup(cup);Whatistheoutput?A.Inconceivable!B.Dizzyingintellect!C.Thecoderunswithnooutput.D.Anexceptionisthrownatruntime.E.Compilationfailsbecauseofanerrorinline22.AQuestion7Given:11.publicstaticvoidtest(Stringstr){12.if(str==null|str.length()==0){//空指针异常|非短路str.length()==0也会执行所以空指针异常13.System.out.println("Stringisempty");14.}else{15.System.out.println("Stringisnotempty");16.}17.}Andtheinvocation:31.test(null);Whatistheresult?A.Anexceptionisthrownatruntime.B."Stringisempty"isprintedtooutput.C.Compilationfailsbecauseofauerrorinline12.D."Stringisnotempty"isprintedtooutput.AQuestion8Given:10.publicclassMyClass{11.12.publicIntegerstartingI;13.publicvoidmethodA(){14.Integeri=newInteger(25);15.startingI=i;16.methodB(i);17.}18.privatevoidmethodB(Integeri2){19.i2=Value();20.21.}22.}IfmethodAisinvoked,whichtwoaretrueatline20?(Choosetwo.)A.i2==startingIreturnstrue.B.i2==startingIreturnsfalse.C.i2.equals(startingI)returnstrue.D.i2.equals(startingI)returnsfalse.BCQuestion9WhichManclassproperlyrepresentstherelationship"ManhasabestfriendwhoisaDog"?A.classManextendsDog{}B.classManimplementsDog{}C.classMan{privateBestFrienddog;}D.classMan{privateDogbestFriend;}E.classMan{privateDog<bestFriend>}F.classMan{privateBestFriend<dog>}//无变量DQuestion10Given:11.publicclassItemTest{12.privatefinalintid;13.publicItemTest(intid){this.id=id;}14.publicvoidupdateId(intnewId){id=newId;}15.16.publicstaticvoidmain(String[]args){17.ItemTestfa=newItemTest(42);18.fa.updateId(69);19.System.out.println(fa.id);20.}21.}Whatistheresult?A.Compilationfails.B.Anexceptionisthrownatruntime.C.TheattributeidintheItemobjectremainsunchanged.D.TheattributeidintheItemobjectismodifiedtothenewvalue.E.AnewItemobjectiscreatedwiththepreferredvalueintheidattribute.AQuestion11Given:15.publicclassYippee{16.publicstaticvoidmain(String[]args){17.for(intx=1;x<args.length;x++){18.System.out.print(args[x]+"");19.}20.}21.}andtwoseparatecommandlineinvocations:javaYippeejavaYippee1234Whatistheresult?A.Nooutputisproduced.123B.Nooutputisproduced.234C.Nooutputisproduced.1234D.Anexceptionisthrownatruntime.123E.Anexceptionisthrownatruntime.234F.Anexceptionisthrownatrijntime.1234BQuestion1212.Given:13.publicclassPass{14.publicstaticvoidmain(String[]args){15.intx=5;16.Passp=newPass();17.p.doStuff(x);18.System.out.print("mainx="+x);19.}20.21.voiddoStuff(intx){22.System.out.print("doStuffx="+x++);23.}24.}Whatistheresult?A.Compilationfails.B.Anexceptionisthrownatruntime.C.doStuffx=6mainx=6D.doStuffx=5mainx=5E.doStuffx=5mainx=6F.doStuffx=6mainx=5DQuestion13Given:10.packagecom.sun.scjp;11.publicclassGeodetics{12.publicstaticfinaldoubleDIAMETER=12756.32;//kilometers13.}WhichtwocorrectlyaccesstheDIAMETERmemberoftheGeodeticsclass?(Choosetwo.)A.importcom.sun.scjp.Geodetics;publicclassTerraCarta{publicdoublehalfway(){returnGeodetics.DIAMETER/2.0;}}B.importstaticcom.sun.scjp.Geodetics;publicclassTerraCarta{publicdoublehalfway(){returnDIAMETER/2.0;}}C.importstaticcom.sun.scjp.Geodetics.*;//static导入类中的所有静态成员publicclassTerraCarta{publicdoublehalfway(){returnDIAMETER/2.0;}}D.packagecom.sun.scjp;publicclassTerraCarta{publicdoublehalfway(){returnDIAMETER/2.0;}}ACQuestion14Given:10.classNav{11.publicenumDirection{NORTH,SOUTH,EAST,WEST}12.}13.publicclassSprite{14.//insertcodehere15.}Whichcode,insertedatline14,allowstheSpriteclasstocompile?A.Directiond=NORTH;B.Nav.Directiond=NORTH;C.Directiond=Direction.NORTH;D.Nav.Directiond=Nav.Direction.NORTH;DQuestion15Given:10.interfaceFoo{intbar();}11.publicclassSprite{12.publicintfubar(Foofoo){returnfoo.bar();}13.publicvoidtestFoo(){14.fubar(15.//insertcodehere16.);17.}18.}Whichcode,insertedatline15,allowstheclassSpritetocompile?A.Foo{publicintbar(){return1;}}B.newFoo{publicintbar(){return1;}}C.newFoo(){publicintbar(){return1;}}//匿名类的使用D.newclassFoo{publicintbar(){return1;}}CQuestion16Given:11.publicclassCounter{12.publicstaticvoidmain(String[]args){13.intnumArgs=/*insertcodehere*/;14.}15.}andthecommandline:javaCounteronefred42Whichcode,insertedatline13,capturesthenumberofargumentspassedintotheprogram?A.args.countB.args.lengthC.args.count()D.args.length()E.args.getLength()BQuestion17Given:1.packagesun.scjp;2.publicenumColor{RED,GREEN,BLUE}1.packagesun.beta;2.//insertcodehere3.publicclassBeta{4.Colorg=GREEN;5.publicstaticvoidmain(String[]argv)6.{System.out.println(GREEN);}7.}TheclassBetaandtheenumColorareindifferentpackages.Whichtwocodefragments,insertedindividuallyatline2oftheBetadeclaration,willallowthiscodetocompile?(Choosetwo.)A.importsun.scjp.Color.*;B.importstaticsun.scjp.Color.*;C.importsun.scjp.Color;importstaticsun.scjp.Color.*;D.importsun.scjp.*;importstaticsun.scjp.Color.*;E.importsun.scjp.Color;importstaticsun.scjp.Color.GREEN;CDEQuestion18Given:1.publicinterfaceA{2.StringDEFAULT_GREETING="HelloWorld";3.publicvoidmethod1();4.}AprogrammerwantstocreateaninterfacecalledBthathasAasitsparent.Whichinterfacedeclarationiscorrect?A.publicinterfaceBextendsA{}B.publicinterfaceBimplementsA{}C.publicinterfaceBinstanceOfA{}D.publicinterfaceBinheritsFromA{}AQuestion19Given:1.classTestA{2.publicvoidstart(){System.out.println("TestA");}3.}4.publicclassTestBextendsTestA{5.publicvoidstart(){System.out.println("TestB");}6.publicstaticvoidmain(String[]args){7.((TestA)newTestB()).start();//TestB对象8.}9.}Whatistheresult?A.TestAB.TestBC.Compilationfails.D.Anexceptionisthrownatruntime.BQuestion20Given:1.interfaceTestA{StringtoString();}2.publicclassTest{3.publicstaticvoidmain(String[]args){4.System.out.println(newTestA(){5.publicStringtoString(){return"test";}6.});7.}8.}Whatistheresult?A.testB.nullC.Anexceptionisthrownatruntime.D.Compilationfailsbecauseofanerrorinline1.E.Compilationfailsbecauseofanerrorinline4.F.Compilationfailsbecauseofanerrorinline5.AQuestion21Given:11.publicabstractclassShape{12.intx;13.inty;14.publicabstractvoiddraw();15.publicvoidsetAnchor(intx,inty){16.this.x=x;17.this.y=y;18.}19.}andaclassCirclethatextendsandfullyimplementstheShapeclass.Whichiscorrect?A.Shapes=newShape();s.setAnchor(10,10);s.draw();B.Circlec=newShape();c.setAnchor(10,10);c.draw();C.Shapes=newCircle();s.setAnchor(10,10);s.draw();D.Shapes=newCircle();s->setAnchor(10,10);s->draw();E.Circlec=newCircle();c.Shape.setAnchor(10,10);c.Shape.draw();CQuestion22Given:10.abstractpublicclassEmployee{11.protectedabstractdoublegetSalesAmount();12.publicdoublegetCommision(){13.returngetSalesAmount()*0.15;14.}15.}16.classSalesextendsEmployee{17.//insertmethodhere18.}Whichtwomethods,insertedindependentlyatline17,correctlycompletetheSalesclass?(Choosetwo.)A.doublegetSalesAmount(){return1230.45;}B.publicdoublegetSalesAmount(){return1230.45;}C.privatedoublegetSalesAmount(){return1230.45;}D.protecteddoublegetSalesAmount(){return1230.45;}BDQuestion23Given:10.interfaceData{publicvoidload();}11.abstractclassInfo{publicabstractvoidload();}WhichclasscorrectlyusestheDatainterfaceandInfoclass?A.publicclassEmployeeextendsInfoimplementsData{publicvoidload(){/*dosomething*/}}B.publicclassEmployeeimplementsInfoextendsData{publicvoidload(){/*dosomething*/}}C.publicclassEmployeeextendsInfoimplementsData{publicvoidload(){/*dosomething*/}publicvoidInfo.load(){/*dosomething*/}}D.publicclassEmployeeimplementsInfoextendsData{publicvoidData.load(){/*dsomething*/}publicvoidload(){/*dosomething*/}}E.publicclassEmployeeimplementsInfoextendsData{publicvoidload(){/*dosomething*/}publicvoidInfo.load(){/*dosomething*/}}F.publicclassEmployeeextendsInfoimplementsData{publicvoidData.load(){/*dosomething*/}publicvoidInfo.load(){/*dosomething*/}}AQuestion24Given:11.publicabstractclassShape{12.privateintx;13.privateinty;14.publicabstractvoiddraw();15.publicvoidsetAnchor(intx,inty){16.this.x=x;17.this.y=y;18.}19.}WhichtwoclassesusetheShapeclasscorrectly?(Choosetwo.)A.publicclassCircleimplementsShape{privateintradius;}B.publicabstractclassCircleextendsShape{privateintradius;}C.publicclassCircleextendsShape{privateintradius;publicvoiddraw();}D.publicabstractclassCircleimplementsShape{privateintradius;publicvoiddraw();}E.publicclassCircleextendsShape{privateintradius;publicvoiddraw(){/*codehere*/}}F.publicabstractclassCircleimplementsShape{privateintradius;publicvoiddraw(){/codehere*/}}BEQuestion25Whichtwoclassescorrectlyimplementboththejava.lang.Runnableandthejava.lang.Clonableinterfaces?(Choosetwo.)A.publicclassSessionimplementsRunnable,Clonable{publicvoidrun();publicObjectclone();}B.publicclassSessionextendsRunnable,Clonable{publicvoidrun(){/dosomething*/}publicObjectclone(){/makeacopy*/}}C.publicclassSessionimplementsRunnable,Clonable{publicvoidrun(){/dosomething*/}publicObjectclone(){/*makeacopy*/}}D.publicabstractclassSessionimplementsRunnable,Clonable{publicvoidrun(){/dosomething*/}publicObjectclone(){/*makeacopy*/}}E.publicclassSessionimplementsRunnable,implementsClonable{publicvoidrun(){/dosomething*/}publicObjectclone(){/makeacopy*/}}CDQuestion261.publicclassGoTest{2.publicstaticvoidmain(String[]args){3.Sentea=newSente();a.go();4.Gobanb=newGoban();b.go();5.Stonec=newStone();c.go();6.}7.}8.9.classSenteimplementsGo{10.publicvoidgo(){System.out.println("goinSente.");}11.}12.13.classGobanextendsSente{14.publicvoidgo(){System.out.println("goinGoban");}15.}16.17.classStoneextendsGobanimplementsGo{}18.19.interfaceGo{publicvoidgo();}Whatistheresult?A.goinGobangoinSentegoinSenteB.goinSentegoinSentegoinGobanC.goinSentegoinGobangoinGobanD.goinGobangoinGobangoinSenteE.Compilationfailsbecauseofanerrorinline17.CQuestion27Given:11.publicstaticvoidparse(Stringstr){12.try{13.floatf=Float.parseFloat(str);14.}catch(NumberFormatExceptionnfe){15.f=0;//f在try里定义这里找不到f16.}finally{17.System.out.println(f);18.}19.}20.publicstaticvoidmain(String[]args){21.parse("invalid");22.}Whatistheresult?A.0.0B.Compilationfails.C.AParseExceptionisthrownbytheparsemethodatruntime.D.ANumberFormatExceptionisthrownbytheparsemethodatruntime.BQuestion281.publicclassTest{2.intx=12;3.publicvoidmethod(intx){4.x+=x;5.System.out.println(x);6.}7.}Given:34.Testt=newTest();35.t.method(5);Whatistheoutputfromline5oftheTestclass?A.5B.10C.12D.17E.24BQuestion29Given:55.int[]x={1,2,3,4,5};56.inty[]=x;57.System.out.println(y[2]);Whichistrue?A.Line57willprintthevalue2.B.Line57willprintthevalue3.C.Compilationwillfailbecauseofanerrorinline55.D.Compilationwillfailbecauseofanerrorinline56.BQuestion30Given:35.String#name="JaneDoe";36.int$age=24;37.Double_height=123.5;38.double~temp=37.5;Whichtwoaretrue?(Choosetwo.)A.Line35willnotcompile.B.Line36willnotcompile.C.Line37willnotcompile.D.Line38willnotcompile.ADQuestion31Whichtwocodefragmentscorrectlycreateandinitializeastaticarrayofintelements?(Choosetwo.)A.staticfinalint[]a={100,200};B.staticfinalint[]a;static{a=newint[2];a[0]=100;a[1]=200;}C.staticfinalint[]a=newint[2]{100,200};//后面已初始int[2]不能给大小D.staticfinalint[]a;staticvoidinit(){a=newint[3];a[0]=100;a[1]=200;}ABQuestion32Given:11.publicclassBall{12.publicenumColor{RED,GREEN,BLUE};13.publicvoidfoo(){14.//insertcodehere15.{System.out.println(c);}16.}17.}Whichcodeinsertedatline14causesthefoomethodtoprintRED,GREEN,andBLUE?A.for(Colorc:Color.values())//枚举的方法B.for(Colorc=RED;c<=BLUE;c++)C.for(Colorc;c.hasNext();c.next())D.for(Colorc=Color[0];c<=Color[2];c++)E.for(Colorc=Color.RED;c<=Color.BLUE;c++)AQuestion33Given:10.publicclassFabric11.publicenumColor{12.RED(0xff0000),GREEN(0x00ff00),BLUE(0x0000ff);13.privatefinalintrgb;14.Color(intrgb){this.rgb=rgb;}15.publicintgetRGB(){returnrgb;}16.};17.publicstaticvoidmain(String[]argv){18.//insertcodehere19.}20.}Whichtwocodefragments,insertedindependentlyatline18,allowtheFabricclasstocompile?(Choosetwo.)A.ColorskyColor=BLUE;B.ColortreeColor=Color.GREEN;C.Colorpurple=newColor(0xff00ff);D.if(RED.getRGB()<BLUE.getRGB()){}E.Colorpurple=Color.BLUE+Color.RED;F.if(Color.RED.ordinal()<Color.BLUE.ordinal()){}//ordinal()下标方法BF单例模式的两种方法:Question34Givenclassesdefinedintwodifferentfiles:1.packageutil;2.publicclassBitUtils{3.publicstaticvoidprocess(byte[]){/*morecodehere*/}4.}1.packageapp;2.publicclassSomeApp{3.publicstaticvoidmain(String[]args){4.byte[]bytes=newbyte[256];5.//insertcodehere6.}7.}Whatisrequiredatline5inclassSomeApptousetheprocessmethodofBitUtils?A.process(bytes);B.BitUcess(bytes);C.util.BitUcess(bytes);D.SomeAppcannotusemethodsinBitUtils.E.importutil.BitUtils.*;process(bytes);CQuestion35Given:11.publicstaticvoidmain(String[]args){12.Objectobj=newint[]{1,2,3};13.int[]someArray=(int[])obj;14.for(inti:someArray)System.out.print(i+"");15.}Whatistheresult?A.123B.Compilationfailsbecauseofanerrorinline12.C.Compilationfailsbecauseofanerrorinline13.D.Compilationfailsbecauseofanerrorinline14.E.AClassCastExceptionisthrownatruntime.AQuestion36Given:10.classFoo{11.staticvoidalpha(){/*morecodehere*/}12.voidbeta(){/*morecodehere*/}13.}Whichtwoaretrue?(Choosetwo.)A.Foo.beta()isavalidinvocationofbeta().B.Foo.alpha()isavalidinvocationofalpha().C.Methodbeta()candirectlycallmethodalpha().D.Methodalpha()candirectlycallmethodbeta().CBQuestion37Aprogrammerneedstocreatealoggingmethodthatcanacceptanarbitrarynumberofarguments.Forexample,itmaybecalledintheseways:logIt("logmessage1");logIt("logmessage2","logmessage3");logIt("logmessage4","logmessage5","logmessage6);Whichdeclarationsatisfiesthisrequirement?A.publicvoidlogIt(String*msgs)B.publicvoidlogIt(String[]msgs)C.publicvoidlogIt(String...msgs)D.publicvoidlogIt(Stringmsg1,Stringmsg2,Stringmsg3)CQuestion38Aprogrammerisdesigningaclasstoencapsulatetheinformationaboutaninventoryitem.AJavaBeanscomponentisneededtodothis.TheInventoryitemclasshasprivateinstancevariablestostoretheiteminformation:10.privateintitemId;11.privateStringname;12.privateStringdescription;WhichmethodsignaturefollowstheJavaBeansnamingstandardsformodifyingtheitemldinstancevariable?A.itemID(intitemId)B.update(intitemId)C.setItemId(intitemId)D.mutateItemId(intitemId)E.updateItemID(intitemId)CQuestion391.publicclassA{2.3.privateintcounter=0;4.5.publicstaticintgetInstanceCount(){6.returncounter;//静态方法里不能使用非静态变量7.}8.9.publicA(){10.counter++;11.}12.13.}GiventhiscodefromClassB:25.Aa1=newA();26.Aa2=newA();27.Aa3=newA();28.System.out.printIn(A.getInstanceCount());Whatistheresult?A.CompilationofclassAfails.B.Line28printsthevalue3toSystem.out.C.Line28printsthevalue1toSystem.out.D.Aruntimeerroroccurswhenline25executes.E.Compilationfailsbecauseofanerroronline28.AQuestion40AJavaBeanscomponenthasthefollowingfield:11.privatebooleanenabled;WhichtwopairsofmethoddeclarationsfollowtheJavaBeansstandardforaccessingthisfield?(Choosetwo.)A.publicvoidsetEnabled(booleanenabled)publicbooleangetEnabled()B.publicvoidsetEnabled(booleanenabled)publicvoidisEnabled()C.publicvoidsetEnabled(booleanenabled)publicbooleanisEnabled()D.publicbooleansetEnabled(booleanenabled)publicbooleangetEnabled()ACQuestion4141.Given:10.classOne{11.publicOnefoo(){returnthis;}12.}13.classTwoextendsOne{14.publicOnefoo(){returnthis;}15.}16.classThreeextendsTwo{17.//insertmethodhere18.}Whichtwomethods,insertedindividually,correctlycompletetheThreeclass?(Choosetwo.)A.publicvoidfoo(){}B.publicintfoo(){return3;}C.publicTwofoo(){returnthis;}D.publicOnefoo(){returnthis;}E.publicObjectfoo(){returnthis;}CDQuestion42Given:10.classOne{11.voidfoo(){}12.}13.classTwoextendsOne{14.//insertmethodhere15.}Whichthreemethods,insertedindividuallyatline14,willcorrectlycompleteclassTwo?(Choosethree.)A.intfoo(){/*morecodehere*/}B.voidfoo(){/*morecodehere*/}C.publicvoidfoo(){/*morecodehere*/}D.privatevoidfoo(){/*morecodehere*/}E.protectedvoidfoo(){/*morecodehere*/}BCEQuestion431.publicinterfaceA{2.publicvoiddoSomething(Stringthing);3.}1.publicclassAImplimplementsA{2.publicvoiddoSomething(Stringmsg){}3.}1.publicclassB{2.publicAdoit(){3.//morecodehere4.}5.6.publicStringexecute(){7.//morecodehere8.}9.}1.publicclassCextendsB{2.publicAImpldoit(){3.//morecodehere4.}5.6.publicObjectexecute(){//不能重写7.//morecodehere8.}9.}Whichstatementistrueabouttheclassesandinterfacesintheexhibit?A.Compilationwillsucceedforallclassesandinterfaces.B.CompilationofclassCwillfailbecauseofanerrorinline2.C.CompilationofclassCwillfailbecauseofanerrorinline6.D.CompilationofclassAImplwillfailbecauseofanerrorinline2.CQuestion441.publicclassA{2.publicStringdoit(intx,inty){3.return"a";4.}5.6.publicStringdoit(int...vals){7.return"b";8.}9.}Given:25.Aa=newA();26.System.out.println(a.doit(4,5));Whatistheresult?A.Line26prints"a"toSystem.out.B.Line26prints"b"toSystem.out.C.Anexceptionisthrownatline26atruntime.D.CompilationofclassAwillfailduetoanerrorinline6.AQuestion45Given:1.publicclassA{2.publicvoiddoit(){3.}4.publicStringdoit(){//不构成重载不能同时存在,参数列表相同5.return"a";6.}7.publicdoubledoit(intx){8.return1.0;9.}10.}Whatistheresult?A.Anexceptionisthrownatruntime.B.Compilationfailsbecauseofanerrorinline7.C.Compilationfailsbecauseofanerrorinline4.D.CompilationsucceedsandnoruntimeerrorswithclassAoccur.CQuestion4646.Given:10.classLine{11.publicstaticclassPoint{}12.}13.14.classTriangle{15.//insertcodehere16.}Whichcode,insertedatline15,createsaninstanceofthePointclassdefinedinLine?A.Pointp=newPoint();B.Line.Pointp=newLine.Point();C.ThePointclasscannotbeinstatiatedatline15.D.Line1=newLine();1.Pointp=new1.Point();BQuestion47Given:10.classLine{11.publicclassPoint{publicintx,y;}12.publicPointgetPoint(){returnnewPoint();}13.}14.classTriangle{15.publicTriangle(){16.//insertcodehere17.}18.}Whichcode,insertedatline16,correctlyretrievesalocalinstanceofaPointobject?A.Pointp=Line.getPoint();B.Line.Pointp=Line.getPoint();C.Pointp=(newLine()).getPoint();D.Line.Pointp=(newLine()).getPoint();DQuestion48Given:10.classOne{11.publicOne(){System.out.print(1);}12.}13.classTwoextendsOne{14.publicTwo(){System.out.print(2);}15.}16.classThreeextendsTwo{17.publicThree(){System.out.print(3);}18.}19.publicclassNumbers{20.publicstaticvoidmain(String[]argv){newThree();}21.}Whatistheresultwhenthiscodeisexecuted?A.1B.3C.123D.321E.Thecoderimswithnooutput.CQuestion4911.classPerson{12.Stringname="Noname";13.publicPerson(Stringnm){name=nm;}//不是无参构造方法14.}15.16.classEmployeeextendsPerson{17.StringemplD="0000";18.publicEmployee(Stringid){empID=id;}//要用super19.}20.21.publicclassEmployeeTest{22.publicstaticvoidmain(String[]args){23.Employeee=newEmployee("4321");24.System.out.println(e.empID);25.}26.}Whatistheresult?A.4321B.0000C.Anexceptionisthrownatruntime.D.Compilationfailsbecauseofanerrorinline18.DQuestion50Given:1.publicclassPlant{2.privateStringname;3.publicPlant(Stringname){=name;}4.publicStringgetName(){returnname;}5.}1.publicclassTreeextendsPlant{2.publicvoidgrowFruit(){}3.publicvoiddropLeaves(){}4.}Whichistrue?A.Thecodewillcompilewithoutchanges.B.ThecodewillcompileifpublicTree(){Plant();}isaddedtotheTreeclass.C.ThecodewillcompileifpublicPlant(){Tree();}isaddedtothePlantclass.D.ThecodewillcompileifpublicPlant(){this("fern");}isaddedtothePlantclass.E.ThecodewillcompileifpublicPlant(){Plant("fern");}isaddedtothePlantclass.DQuestion5111.publicclassBootchy{12.intbootch;13.Stringsnootch;14.15.publicBootchy(){16.this("snootchy");17.System.out.print("first");18.}19.20.publicBootchy(Stringsnootch){21.this(420,"snootchy");22.System.out.print("second");23.}24.25.publicBootchy(intbootch,Stringsnootch){26.this.bootch=bootch;27.this.snootch=snootch;28.System.out.print("third");29.}30.31.publicstaticvoidmain(String[]args){32.Bootchyb=newBootchy();33.System.out.print(b.snootch+""+b.bootch);34.}35.}Whatistheresult?A.snootchy420thirdsecondfirstB.snootchy420firstsecondthirdC.firstsecondthirdsnootchy420D.thirdsecondfirstsnootchy420E.thirdfirstsecondsnootchy420F.firstsecondfirstthirdsnootchy420DQuestion52Given:1.importjava.util.*;2.3.publicclassLetterASort{4.publicstaticvoidmain(String[]args){5.ArrayList<String>strings=newArrayList<String>();6.strings.add("aAaA");7.strings.add("AaA");8.strings.add("aAa");9.strings.add("AAaa");10.Collections.sort(strings);11.for(Strings:strings){System.out.print(s+"");}12.}13.}Whatistheresult?A.Compilationfails.B.aAaAaAaAAaaAaAC.AAaaAaAaAaaAaAD.AaAAAaaaAaAaAaE.aAaAaAaAaAAAaaF.Anexceptionisthrownatruntime.CQuestion53Given:int[]myArray=newint[]{1,2,3,4,5};Whatallowsyoutocreatealistfromthisarray?A.ListmyList=myArray.asList();B.ListmyList=Arrays.asList(myArray);//数组转ListC.ListmyList=newArrayList(myArray);D.ListmyList=Collections.fromArray(myArray);BQuestion54Given:1.publicclassDrinkimplementsComparable{2.publicStringname;3.publicintcompareTo(Objecto){4.return0;5.}6.}and:20.Drinkone=newDrink();21.Drinktwo=newDrink();22.="Coffee";23.="Tea";23.TreeSetset=newTreeSet();24.set.add(one);25.set.add(two);//集合不能出现重复的项,return0;表示集合中最多只有一项。AprogrammeriteratesovertheTreeSetandprintsthenameofeachDrinkobject.Whatistheresult?A.TeaB.CoffeeC.CoffeeTeaD.Compilationfails.E.Thecoderunswithnooutput.F.Anexceptionisthrownatruntime.BQuestion55Given:11.publicstatic

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论