SCJP模拟试题.docx
- 文档编号:9697000
- 上传时间:2023-02-05
- 格式:DOCX
- 页数:165
- 大小:788.05KB
SCJP模拟试题.docx
《SCJP模拟试题.docx》由会员分享,可在线阅读,更多相关《SCJP模拟试题.docx(165页珍藏版)》请在冰豆网上搜索。
SCJP模拟试题
Question1
Given:
11.publicinterfaceStatus{
12./*insertcodehere*/intMY_VALUE=10;
13.}
Whichthreearevalidonline12?
(Choosethree.)
A.final
B.static
C.native
D.public
E.private
F.abstract
G.protected
Question2
Given:
10.publicclassBar{
11.staticvoidfoo(int...x){
12.//insertcodehere
13.}
14.}
Whichtwocodefragments,insertedindependentlyatline12,willallow
theclasstocompile?
(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 Question3 Given: 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.2 B.3 C.12 D.23 E.123 F.Compilationfails. G.Auexceptionalisthrownatruntime. Question4 4.Given: 31.//somecodehere 32.try{ 33.//somecodehere 34.}catch(SomeExceptionse){ 35.//somecodehere 36.}finally{ 37.//somecodehere 38.} Underwhichthreecircumstanceswillthecodeonline37beexecuted? (Choosethree.) A.Theinstancegetsgarbagecollected. B.Thecodeonline33throwsanexception. C.Thecodeonline35throwsanexception. D.Thecodeonline31throwsanexception. E.Thecodeonline33executessuccessfully. Question5 Given: 10.interfaceFoo{} 11.classAlphaimplementsFoo{} 12.classBetaextendsAlpha{} 13.classDeltaextendsBeta{ 14.publicstaticvoidmain(String[]args){ 15.Betax=newBeta(); 16.//insertcodehere 17.} 18.} Whichcode,insertedatline16,willcausea java.lang.ClassCastException? A.Alphaa=x; B.Foof=(Delta)x; C.Foof=(Alpha)x; D.Betab=(Beta)(Alpha)x; Question6 Given: •disavalid,non-nullDateobject •dfisavalid,non-nullDateFormatobjectsettothe currentlocale Whatoutputsthecurrentlocalescountrynameandtheappropriate versionofd’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)); Question7 Given: 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. Question8 Assumethatcountryissetforeachclass. 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. Question9 WhichManclassproperlyrepresentstherelationship“Manhasabest friendwhoisaDog”? A.classManextendsDog{} B.classManimplementsDog{} C.classMan{privateBestFrienddog;} D.classMan{privateDogbestFriend;} E.classMan{privateDog F.classMan{privateBestFriend Question10 Given: 11.publicclassPerson{ 12.privatename; 13.publicPerson(Stringname){ 14.this.name=name; 15.} 16.publicinthashCode(){ 17.return420; 18.} 19.} Whichistrue? A.ThetimetofindthevaluefromHashMapwithaPersonkeydepends onthesizeofthemap. B.DeletingaPersonkeyfromaHashMapwilldeleteallmapentriesfor allkeysoftypePerson. C.InsertingasecondPersonobjectintoaHashSetwillcausethefirst Personobjecttoberemovedasaduplicate. D.ThetimetodeterminewhetheraPersonobjectiscontainedina HashSetisconstantanddoesNOTdependonthesizeofthemap. Question11 Given: 23.Object[]myObjects={ 24.newinteger(12), 25.newString(”foo”), 26.newinteger(5), 27.newBoolean(true) 28.}; 29.Arrays.sort(myObjects); 30.for(inti=0;i 31.System.out.print(myObjects[i].toString()); 32.System.out.print(”“); 33.} Whatistheresult? A.Compilationfailsduetoanerrorinline23. B.Compilationfailsduetoanerrorinline29. C.AClassCastExceptionoccursinline29. D.AClassCastExceptionoccursinline31. E.Thevalueofallfourobjectsprintsinnaturalorder. Question12 12.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=6 D.doStuffx=5mainx=5 E.doStuffx=5mainx=6 F.doStuffx=6mainx=5 Question13 Given: 10.packagecom.sun.scjp; 11.publicclassGeodetics{ 12.publicstaticfinaldoubleDIAMETER=12756.32;//kilometers 13.} WhichtwocorrectlyaccesstheDIAMETERmemberoftheGeodetics class? (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.*; publicclassTerraCarta{ publicdoublehalfway(){returnDIAMETER/2.0;}} D.packagecom.sun.scjp; publicclassTerraCarta{ publicdoublehalfway(){returnDIAMETER/2.0;}} Question14 Given: 10.classNav{ 11.publicenumDirection{NORTH,SOUTH,EAST,WEST} 12.} 13.publicclassSprite{ 14.//insertcodehere 15.} Whichcode,insertedatline14,allowstheSpriteclasstocompile? A.Directiond=NORTH; B.Nav.Directiond=NORTH; C.Directiond=Direction.NORTH; D.Nav.Directiond=Nav.Direction.NORTH; Question15 Given: 10.interfaceFoo{intbar();} 11.publicclassSprite{ 12.publicintfubar(Foofoo){returnfoo.bar();} 13.publicvoidtestFoo(){ 14.fubar( 15.//insertcodehere 16.); 17.} 18.} Whichcode,insertedatline15,allowstheclassSpritetocompile? A.Foo{publicintbar(){return1;}} B.newFoo{publicintbar(){return1;}} C.newFoo(){publicintbar(){return1;}} D.newclassFoo{publicintbar(){return1;}} Question16 ClicktheExhibitbutton. 10.interfaceFoo{ 11.intbar(); 12.} 13. 14.publicclassBeta{ 15. 16.classAimplementsFoo{ 17.publicintbar(){return1;} 18.} 19. 20.publicintfubar(Foofoo){returnfoo.bar();} 21. 22.publicvoidtestFoo(){ 23. 24.classAimplementsFoo{ 25.publicintbar(){return2;} 26.} 27. 28.System.out.println(fubar(newA())); 29.} 30. 31.publicstaticvoidmain(String[]argv){ 32.newBeta().testFoo(); 33.} 34.} Whichthreestatementsaretrue? (Choosethree.) A.Compilationfails. B.Thecodecompilesandtheoutputis2. C.Iflines16,17and18wereremoved,compilationwouldfail. D.Iflines24,25and26wereremoved,compilationwouldfail. E.Iflines16,17and18wereremoved,thecodewouldcompileand theoutputwouldbe2. F.Iflines24,25and26wereremoved,thecodewouldcompileand theoutputwouldbe1. Question17 Given: 1.packagesun.scjp; 2.publicenumColor{RED,GREEN,BLUE} 1.packagesun.beta; 2.//insertcodehere 3.publicclassBeta{ 4.Colorg=GREEN; 5.publicstaticvoidmain(String[]argv) 6.{System.out.println(GREEN);} 7.} TheclassBetaandtheenumColorareindifferentpackages. Whichtwocodefragments,insertedindividuallyatline2oftheBeta declaration,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; Question18 Given: 1.publicinterfaceA{ 2.StringDEFAULT_GREETING=“HelloWorld”; 3.publicvoidmethod1(); 4.} AprogrammerwantstocreateaninterfacecalledBthathasAasits parent.Whichinterfacedeclarationiscorrect? A.publicinterfaceBextendsA{} B.publicinterfaceBimplementsA{} C.publicinterfaceBinstanceOfA{} D.publicinterfaceBinheritsFromA{} Question19 Given: 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(); 8.} 9.} Whatistheresult? A.TestA B.TestB C.Compilationfails. D.Anexceptionisthrownat
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- SCJP 模拟 试题