您好,欢迎访问三七文档
1Question1Given:11.publicinterfaceStatus{12./*insertcodehere*/intMY_VALUE=10;13.}Whichthreearevalidonline12?(Choosethree.)A.finalB.staticC.nativeD.publicE.privateF.abstractG.protectedQuestion2Given: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;ix.length;i++)System.out.println(x[i]);Question3Given: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.Question44.Given:31.//somecodehere32.try{33.//somecodehere34.}catch(SomeExceptionse){35.//somecodehere36.}finally{37.//somecodehere38.}Underwhichthreecircumstanceswillthecodeonline37beexecuted?(Choosethree.)A.Theinstancegetsgarbagecollected.B.Thecodeonline33throwsanexception.C.Thecodeonline35throwsanexception.D.Thecodeonline31throwsanexception.E.Thecodeonline33executessuccessfully.Question5Given: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;C.Foof=(Alpha)x;D.Betab=(Beta)(Alpha)x;Question6Given:2•disavalid,non-nullDateobject•dfisavalid,non-nullDateFormatobjectsettothecurrentlocaleWhatoutputsthecurrentlocalescountrynameandtheappropriateversionofd’sdate?A.Localeloc=Locale.getLocale();System.out.println(loc.getDisplayCountry()+““+df.format(d));B.Localeloc=Locale.getDefault();System.out.println(loc.getDisplayCountry()+““+df.format(d));C.Localebc=Locale.getLocale();System.out.println(loc.getDisplayCountry()+““+df.setDateFormat(d));D.Localeloc=Locale.getDefault();System.out.println(loc.getDispbayCountry()+““+df.setDateFormat(d));Question7Given:20.publicclassCreditCard{21.22.privateStringcardlD;23.privateIntegerlimit;24.publicStringownerName;25.26.publicvoidsetCardlnformation(StringcardlD,27.StringownerName,28.Integerlimit){29.this.cardlD=cardlD;30.this.ownerName=ownerName;31.this.limit=limit;32.}33.}Whichistrue?A.Theclassisfullyencapsulated.B.Thecodedemonstratespolymorphism.C.TheownerNamevariablebreaksencapsulation.D.ThecardlDandlimitvariablesbreakpolymorphism.E.ThesetCardlnformationmethodbreaksencapsulation.Question8Assumethatcountryissetforeachclass.Given:10.publicclassMoney{11.privateStringcountry,name;12.publicgetCountry(){returncountry;}13.}and:24.classYenextendsMoney{25.publicStringgetCountry(){returnsuper.country;}26.}27.28.classEuroextendsMoney{29.publicStringgetCountry(StringtimeZone){30.returnsuper.getCountry();31.}32.}Whichtwoarecorrect?(Choosetwo.)A.Yenreturnscorrectvalues.B.Euroreturnscorrectvalues.C.Anexceptionisthrownatruntime.D.YenandEurobothreturncorrectvalues.E.Compilationfailsbecauseofanerroratline25.F.Compilationfailsbecauseofanerroratline30.Question9WhichManclassproperlyrepresentstherelationship“ManhasabestfriendwhoisaDog”?A.classManextendsDog{}B.classManimplementsDog{}C.classMan{privateBestFrienddog;}D.classMan{privateDogbestFriend;}E.classMan{privateDogbestFriend}F.classMan{privateBestFrienddog}Question10Given:11.publicclassPerson{12.privatename;13.publicPerson(Stringname){14.this.name=name;15.}16.publicinthashCode(){17.return420;18.}19.}Whichistrue?A.ThetimetofindthevaluefromHashMapwithaPersonkeydependsonthesizeofthemap.3B.DeletingaPersonkeyfromaHashMapwilldeleteallmapentriesforallkeysoftypePerson.C.InsertingasecondPersonobjectintoaHashSetwillcausethefirstPersonobjecttoberemovedasaduplicate.D.ThetimetodeterminewhetheraPersonobjectiscontainedinaHashSetisconstantanddoesNOTdependonthesizeofthemap.Question11Given:23.Object[]myObjects={24.newinteger(12),25.newString(”foo”),26.newinteger(5),27.newBoolean(true)28.};29.Arrays.sort(myObjects);30.for(inti=0;imyObjects.length;i++){31.System.out.print(myObjects[i].toString());32.System.out.print(”“);33.}Whatistheresult?A.Compilationfailsduetoanerrorinline23.B.Compilationfailsduetoanerrorinline29.C.AClassCastExceptionoccursinline29.D.AClassCastExceptionoccursinline31.E.Thevalueofallfourobjectsprintsinnaturalorder.Question1212.Given:13.publicclassPass{14.publicstaticvoidmain(String[1args){15.intx5;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=5Question13Given:10.packagecom.sun.scjp;11.publicclassGeodetics{12.publicstaticfinaldoubleDIAMETER=12756.32;//kilometers13.}WhichtwocorrectlyaccesstheDIAMETERmemberoftheGeodeticsclass?(Choosetwo.)A.importcom.sun.s
本文标题:scjp模拟试题
链接地址:https://www.777doc.com/doc-6107833 .html