版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
試卷科目:OracleOCA認(rèn)證考試練習(xí)OracleOCA認(rèn)證考試練習(xí)真題題庫(kù)一PAGE"pagenumber"pagenumber/SECTIONPAGES"numberofpages"numberofpagesOracleOCA認(rèn)證考試練習(xí)真題題庫(kù)一第1部分:?jiǎn)雾?xiàng)選擇題,共241題,每題只有一個(gè)正確答案,多選或少選均不得分。[單選題]1.Given:publicclassTestTry{publicstaticvoidmain(String[]args){StringBuildermessage=newStringBuilder("hellojava!");intpos=0;try{for(pos=0;pos<12;pos++){switch(message.charAt(pos)){case'a':case'e':case'o':Stringuc=Character.toString(message.charAt(pos)).toUpperCase();message.replace(pos,pos+1,uc);}}}catch(Exceptione){System.out.println("Outoflimits");}System.out.println(message);}}Whatistheresult?A)hEllOjAvA!B)Hellojava!C)OutoflimitshEllOjAvA!D)Outoflimits答案:C解析:[單選題]2.Giventhecodefragment:publicclassTest{2.publicstaticvoidmain(String[]args){3./*insertcodehere*/4.array[0]=10;5.array[1]=20;6.System.out.print(array[0]+":"+array[1]);7.}8.}Whichcodefragment,wheninsertedatline3,enablesthecodetoprint10:20?A)int[]array=newint[2];B)int[]array;array=int[2];C)intarray=newint[2];D)intarray[2];答案:A解析:[單選題]3.Given:Classx{staticinti;intj;publicstaticvoidmain(String[]args){Xx1=newX();Xx2=newX();x1.i=3;x1.j=4;x2.1=5;x2.j=6;System.out.println(x1.i+""+x1.j+""+x2.i+""+x2.j);}}Whatistheresult?A)3456B)3436C)5456D)3646答案:C解析:[單選題]4.Given:PublicclassCharToStr{publicstaticvoidmain(String[]args){Stringstr1="Java";charstr2[]={'J','a','v','a'};Stringstr3=null;for(charc:str2){str3=str3+c;}if(str1.equals(str3))System.out.print("Successful");elseSystem.out.print("Unsuccessful");}}Whatisresult?A)SuccessfulB)UnsuccessfulC)CompilationfailsD)Anexceptionisthrownat答案:B解析:[單選題]5.Given:ClassSports{Intnum_players;Stringname,ground_condition;Sports(intnp,Stringsname,Stringsground){Num_players=np;Name=sname;Ground_condition=sground;}}ClassCricketextendsSports{Intnum_umpires;Intnum_substitutes;}Whichcodefragmentcanbeinsertedatline//insertcodeheretoenablethecodetocompile?A)Cricket(){Super(11,"Cricket","CondidtionOK");num_umpires=3;num_substitutes=2;}B)Cricket(){Super.ground_condition="ConditionOK";="Cricket";super.num_players=11;Num_umpires=3;num_substitutes=2;}C)Cricket(){this(3,2);Super(11,"Cricket","CondidtionOK");}Cricket(intnu,ns){this.num_umpires=nu;this.num_substitutes=ns;}D)Cricket(){this.num_umpires=3;this.num_substitutes=2;Super(11,"Cricket","CondidtionOK");}答案:A解析:[單選題]6.Given:PublicclassCalculator{Publicstaticvoidmain(String[]args){Intnum=5;Intsum;Do{Sum+=num;}while((num--)>1);System.out.println("Thesumis"+sum+".");}}Whatistheresult?A)Thesumis2B)Thesumis14C)Thesumis15D)TheloopexecutesinfiniteE)Compilationfails答案:E解析:[單選題]7.Giventhecodefragment:PublicclassTest{Staticintcount=0;Inti=0;PublicvoidchangeCount(){While(i<5){I++;Count++;}}Publicstaticvoidmain(String[]args){Testcheck1=newTest();Testcheck2=newTest();Check1.changeCount();Check2.changeCount();System.out.print(check1.count+?:?+check2.count);}}Whatistheresult?A)10:10B)5:5C)5:10D)Compilationfails答案:A解析:[單選題]8.int[]array={1,2,3,4,5};for(inti:array){If(i<2){keyword1;}System.out.println(i);If(i==3){keyword2;}}Whatshouldkeyword1andkeyword2berespectively,inoredertoproduceoutput2345?A)continue,breakB)break,breakC)break,continueD)continue,continue答案:D解析:[單選題]9.9.Giventheclassdefinitions:classAlpha{publicStringdoStuff(Stringmsg){returnmsg;}}classBetaextendsAlpha{publicStringdoStuff(Stringmsg){returnmsg.replace('a','e');}}classCammaextendsBeta{publicStringdoStuff(Stringmsg){returnmsg.substring(2);}}Andthecodefragmentofthemain()method,12.List<Alpha>strs=newArrayList<Alpha>();13.strs.add(newAlpha());14.strs.add(newBeta());15.strs.add(newGamma());16.for(Alphat:strs){17.System.out.println(t.doStuff("Java"));18.}Whatistheresult?A)JavaJavaJavaB)JavaJevevaC)JavaJeveveD)Compilationfails答案:B解析:[單選題]10.Given:ClassMarksOutOfBoundsExceptionextendsIndexOutOfBoundsException{}publicclassGradingProcess{Voidverify(intmarks)throwsIndexOutOfBoundsException{if(marks>100){ThrownewMarksOutOfBoundsException();}If(marks>50){System.out.print("Pass");}else{System.out.print("Fail");}}Publicstaticvoidmain(String[]args){intmarks=Integer.parseInt(args[2]);try{NewGradingProcess().verify(marks));}catch(Exceptione){System.out.print(e.getClass());}}}Andthecommandlineinvocation:Javagradingprocess8950104Whatistheresult?A)PassB)FailC)ClassMarketOutOfBoundsExceptionD)ClassIndexOutOfBoundsExceptionE)ClassException答案:C解析:Thevalue104willcauseaMarketOutOfBoundsException[單選題]11.Given:ClassStar{Publicvoiddostuff(){System.out.println("Twinklingstar");}}InterfaceUniverse{Publicvoiddostuff();}ClassSunextendsStarimplementsUniverse{Publicvoiddostuff(){System.out.println("Shiningsun");}}PublicclassBob{Publicstaticvoidmain(String[]args){Sunobj2=newSun();Starobj3=obj2;((Sun)obj3).dostuff();((Star)obj2).dostuff();((Universe)obj2).dostuff();}}Whatistheresult?A)ShiningSunShiningSunShiningSunB)ShiningSunTwinklingStarShiningSunC)CompilationfailsD)AClassCastExceptionisthrownatruntime答案:A解析:[單選題]12.Given:PublicclassTest1{Staticvoiddoubling(Integerref,intpv){ref=20;Pv=20;}Publicstaticvoidmain(String[]args){IntegeriObj=newInteger(10);IntiVar=10;doubling(iObj++,iVar++);System.out.println(iObj+","+iVar);Whatistheresult?A)11,11B)10,10C)21,11D)20,20E)11,12答案:A解析:Thecodedoubling(iObj++,iVar++);increasesbothvariablesfromto10to11.[單選題]13.Given:Intx=10;If(x>10){System.out.println(">");}elseif(x<10){System.out.println("<");}esle{System.out.println("=");}Whichofthefollowingisequivalenttotheabovecodefragment?A)System.out.printLn(x>10?">,':"<":,'=");B)System.out.println(x>10?">"?"<":"=");C)System.out.println(x>10?">":x<10?"<":"=");D)System.out.printLn(x>10?">"?,'<"?"=");E)Noneoftheabove答案:C解析:OptionAisincorrectaswecan'tuseabstractwithnonabstractmethod,(heremethodhasmethodbody.)OptionCisincorrectaswhenoverridingmethodwecan'tusemorerestrictiveaccessmodifier,sotryingtouseprivatetooverridedefaultaccessLevelmethodcausesacompiletimeerror.OptionDisincorrectasdefaultmethods(notmethodswithdefaultaccesslevel)areallowedonlyininterfaces.OptionEisincorrectasmethodallreadyhasvoidasreturntype,sowecan'taddintthere.OptionBiscorrectaswecanusefinalthere,sincethemethodisnonabstract/javase/tutorial/java/landl/polymorphism.html[單選題]14.12.Giventhecodefragment:intnum[][]=newint[1][3];for(inti=0;i<num.length;i++){for(intj=0;j<num[i].length;j++){num[i][j]=10;}}Whichoptionrepresentsthestateofthenumarrayaftersuccessfulcompletionoftheouterloop?A)num[0][0]=10num[0][1]=10num[0][2]=10B)num[0][0]=10num[1][0]=10num[2][0]=10C)num[0][0]=10num[0][1]=0num[0][2]=0D)num[0][0]=10num[0][1]=10num[0][2]=10num[0][3]=10num[1][0]=0num[1][1]=0num[1][2]=0num[1][3]=0答案:A解析:[單選題]15.Given:PublicclassTest3{Publicstaticvoidmain(String[]args){Stringnames[]=newString[3];Names[0]="MaryBrown";Names[1]="NancyRed";Names[2]="JseeyOrange";Try{For(Stringn:names){Try{Stringpwd=n.substring(0,3)+n.substring(6,10);System.out.println(pwd);}catch(StringIndexOutOfBoundsExceptionsie){System.out.println("stringoutoflimits");}}}catch(ArrayIndexOutOfBoundsExceptione){System.out.println("arrayoutoflimits");}}}Whatistheresult?A)MarrownStringoutoflimitsJesOranB)MarrownStringoutoflimitsArrayoutoflimitsC)MarrownStringoutoflimitsD)MarrownNanRedJesOran答案:A解析:[單選題]16.Giventhecodefragment:Publicstaticvoidmain(String[]args){IntiArray[]={65,68,69};IArray[2]=iArray[0];IArray[0]=iArray[1];IArray[1]=iArray[2];For(intelement:iArray){System.out.print(element+"");}A)68,65,69B)68,65,65C)65,68,65D)65,68,69E)Compilationfails答案:B解析:[單選題]17.Given:PublicclassNatural{Privateinti;Voiddisp(){While(i<=5){For(inti=1;i<=5;){System.out.print(i+"");I++;}I++;}}Publicstaticvoidmain(String[]args){NewNatural().disp();}}Whatistheresult?A)Prints12345onceB)Prints135onceC)Prints12345fivetimesD)Prints12345sixtimesE)Compilationfails答案:D解析:123451234512345123451234512345[單選題]18.Given:PublicclassVowel{Privatecharvar;Publicstaticvoidmain(String[]args){Charvar1='a';Charvar2=var1;Var2='e';Vowelobj1=newVowel();Vowelobj2=newVowel();Obj1.var='i';Obj2.var='o';System.out.println(var1+","+var2);System.out.println(obj1.var+","+obj2.var);}}A)a,ei,oB)a,eo,oC)e,eI,oD)e,eo,o答案:A解析:[單選題]19.Given:ClassPatient{Stringname;publicPatient(Stringname){=name;}}PublicclassTest15{publicstaticvoidmain(String[]args){Listps=newArrayList();Patientp2=newPatient("Mike");ps.add(p2);if(f>=0){System.out.println("MikeFound");}}}Whichcodefragment,wheninsertedatline14,enablesthecodetoprintMikeFound?A)intf=ps.indexOf{newpatient(?Mike?)};B)intf=ps.indexOf(patient(?Mike?));C)patientp=newPatient(?Mike?);intf=pas.indexOf(P)D)intf=ps.indexOf(p2);答案:D解析:[單選題]20.Given:PublicclassTest{Publicstaticvoidmain(String[]args){try{String[]arr=newString[4];arr[1]="Unix";Arr[2]="Linux";Arr[3]="Solarios";For(Stringvar:arr){System.out.print(var+"");}}catch(Exceptione){System.out.print(e.getClass());}}}Whatistheresult?A)UnixLinuxSolarisB)NullUnixLinuxSolarisC)Classjava.lang.ExceptionD)Classjava.lang.NullPointerException答案:B解析:nullUnixLinuxSolariosThefirstelement,arr[0],hasnotbeendefined.[單選題]21.Given:PublicclassTestOperator{Publicstaticvoidmain(String[]args){intresult=30-12/(2*5)+1;System.out.print("Result="+result);}}Whatistheresult?A)Result=2B)Result=3C)Result=28D)Result=29E)Result=30答案:E解析:[單選題]22.Giventhecodefragment:intb=3;If(!(b>3)){System.out.println("square");}{System.out.println("circle");}System.out.println("...");Whatistheresult?A)square...B)circle...C)squarecircle...D)Compilationfails.答案:C解析:[單選題]23.Given:Importjava.util.*;PublicclassRef{Publicstaticvoidmain(String[]args){StringBuilders1=newStringBuilder("HelloJava!");Strings2=s1.toString();List<String>lst=newArrayList<String>();Lst.add(s2);System.out.println(s1.getClass());System.out.println(s2.getClass());System.out.println(lst.getClass());}}Whatistheresult?A)classjava.lang.Stringclassjava.lang.Stringclassjava.util.ArrayListB)classjava.lang.Objectclassjava.lang.Objectclassjava.util.CollectionC)classjava.lang.StringBuilderclassjava.lang.StringClassjava.util.ArrayListD)classjava.lang.StringBuilderclassjava.lang.StringClassjava.util.List答案:C解析:classjava.lang.StringBuilderclassjava.lang.StringClassjava.util.ArrayList[單選題]24.Given:PublicclassMainMethod{voidmain(){System.out.println("one");}Staticvoidmain(Stringargs){System.out.println("two");}Publicstaticvoidmain(String[]args){System.out.println("three");}Voidmina(Object[]args){System.out.println("four");}}Whatisprintedoutwhentheprogramisexcuted?A)oneB)twoC)threeD)four答案:C解析:[單選題]25.Given:PublicclassTest{Publicstaticvoidmain(String[]args){Intarr[]=newint[4];Arr[0]=1;Arr[1]=2;Arr[2]=4;Arr[3]=5;Intsum=0;Try{For(intpos=0;pos<=4;pos++){sum=sum+arr[pos];}}catch(Exceptione){System.out.println("Invalidindex");}System.out.println(sum);}}Whatistheresult?A)12B)InvalidIndex12C)InvalidIndexD)Compilationfails答案:B解析:Theloop(for(intpos=0;pos<=4;pos++){),itshouldbepos<=3,causesanexception,whichiscaught.Thenthecorrectsumisprinted.[單選題]26.Giventhecodefragment:ClassStudent{Stringname;Intage;}And,PublicclassTestP{Publicstaticvoidmain(String[]args){Students1=newstudent();Students2=newstudent();Students3=newstudent();S1=s3;S3=s2;S2=null;}}Whichstatementistrue?A)Afterline8,threeobjectsareeligibleforgarbagecollectionB)Afterline8,twoobjectsareeligibleforgarbagecollectionC)Afterline8,oneobjectiseligibleforgarbagecollectionD)Afterline8,noneoftheobjectsareeligibleforgarbagecollection答案:C解析:[單選題]27.Given:PublicclassTest{staticbooleanbVar;Publicstaticvoidmain(String[]args){BooleanbVar1=true;intcount=8;Do{System.out.println("HelloJava!"+count);if(count>=7){BVar1=false;}}while(bVar!=bVar1&&count>4);count-=2;}}Whatistheresult?A)HelloJava!8HelloJava!6HelloJava!4B)HelloJava!8HelloJava!6C)HelloJava!8D)Compilationfails答案:C解析:HelloJava!8[單選題]28.Given:PublicclassTest2{publicstaticvoidmain(String[]args){intar1[]={2,4,6,8};intar2[]={1,3,5,7,9};ar2=ar1;for(inte2:ar2){System.out.print(""+e2);}}}Whatistheresult?A)2468B)24689C)1357D)13579答案:A解析:[單選題]29.Giventhecodefragment:Publicstaticvoidmain(String[]args){booleanopt=true;switch(opt){casetrue;System.out.print("True");break;default:System.out.print("***");}System.out.println("Done");}WhichmodificationenablesthecodefragmenttoprintTrueDone?A)Replaceline5WithStringresult="true";Replaceline7withcase"true":B)Replaceline5withbooleanopt=l;Replaceline7withcase1=C)Atline9,removethebreakstatement.D)Removethedefaultsection.答案:A解析:[單選題]30.Giventhecodefragment:Listcolors=newArrayList();Colors.add("green");Colors.add("red");Colors.add("blue");Colors.add("yellow");Colors.remove(2);Colors.add(3,"cyan");System.out.print(colors);Whatistheresult?A)[green,red,yellow,cyan]B)[green,blue,yellow,cyan]C)[green,red,cyan,yellow]D)AmIndexOutOfBoundsExceptionisthrownatruntime答案:A解析:Firstthelist[green,red,blue,yellow]isbuild.Theblueelementisremoved:[green,red,yellow]Finallytheelementcyanisaddedatthenendofthelist(index3).[green,red,yellow,cyan][單選題]31.GiventhefollowingfourJavafiledefinitions://Foo.javapackagefacades;PublicinterfaceFoo{}//Boo.javapackagefacades;PublicinterfaceBooextendsFoo{}//Woofy.javapackageorg.domain//linen1PublicclassWoofyimplementsBoo,Foo{}//Test.java;publicclassTest{Publicstaticvoidmain(String[]args){Fooobj=newWoofy();Whichsetmodificationsenablethecodetocompileandrun?A)Atlinen1,Insert:importfacades;Atlinen2,insert:importfacades;importorg.domain;B)Atlinen1,Insert:importfacades.*;Atlinen2,insert:importfacades;importorg.*;C)Atlinen1,Insert:importfacades.*;Atlinen2,insert:importfacades.Boo;importorg.*;D)Atlinen1,Insert:importfacades.Foo,Boo;Atlinen2,insert:importorg.domain.Woofy;E)Atlinen1,Insert:importfacades.*;Atlinen2,insert:importfacades;importorg.domain.Woofy;答案:E解析:[單選題]32.Giventhecodefragment:StringBuildersb=newStringBuilder();Sb.append(?world?);WhichcodefragmentprintsHelloWorld?A)sb.insert(0,"Hello");System.out.println(sb);B)sb.append(0,"Hello");System.out.println(sb);C)sb.add(0,"Hello");System.out.println(sb);D)sb.set(0,"Hello");System.out.println(sb);D答案:A解析:Thejava.lang.StringBuilder.insert(intoffset,charc)methodinsertsthestringrepresentationofthecharargumentintothissequence.Thesecondargumentisinsertedintothecontentsofthissequenceatthepositionindicatedbyoffset.Thelengthofthissequenceincreasesbyone.Theoffsetargumentmustbegreaterthanorequalto0,andlessthanorequaltothelengthofthissequence.Reference:Java.lang.StringBuilder.insert()Method[單選題]33.Giventhefragments:PublicclassTestAextendsRoot{Publicstaticvoidmain(String[]args){Rootr=newTestA();System.out.println(r.method1());//linen1System.out.println(r.method2());//linen2}}ClassRoot{PrivatestaticfinalintMAX=20000;Privateintmethod1(){Inta=100+MAX;Returna;}Protectedintmethod2(){Inta=200+MAX;Returna;}}Whichlinecausesacompilationerror?A)Linen1B)Linen2C)Linen3D)Linen4答案:A解析:[單選題]34.Given:Publicstaticvoidmain(String[]args){String[][]chs=newString[2][];Chs[0]=newString[2];Chs[1]=newString[5];Inti=97;For(inta=0;a<chs.length;a++){For(intb=0;b<chs.length;b++){Chs[a][b]=""+i;I++;}}For(String[]ca:chs){For(Stringc:ca){System.out.println(c+"");}System.out.println();}}}Whatistheresult?A)979899100nullnullnullB)919899100101102103C)Compilationrails.D)ANullPointerExceptionisthrownatruntime.E)AnArraylndexOutOfBoundsExceptionisthrownatruntime.答案:A解析:[單選題]35.Giventhecodefragment:PublicclassTest{VoidreadCard(intcardNo)throwsException{System.out.println("ReadingCard");}VoidcheckCard(intcardNo)throwsRuntimeException{//linen1//運(yùn)行時(shí)異常System.out.println("CheckingCard");}Publicstaticvoidmain(String[]args){Testex=newTest();IntcardNo=12344;Ex.checkCard(cardNo);//linen2Ex.readCard(cardNo);//linen3}}Whatistheresult?A)ReadingCardCheckingCardB)Compilationfailsonlyatlinen1.C)Compilationfailsonlyatlinen2.D)Compilationfailsonlyatlinen3.E)Compilationfailsatbothlinen2andlinen3.答案:D解析:[單選題]36.Given:PublicclassTest{StaticvoiddispResult(int[]num){try{System.out.println(num[1]/(num[1]-num[2]));}catch(ArithmeticExceptione){System.out.println("firstexception");}System.out.println("Done");}Publicstaticvoidmain(String[]args){Try{Int[]arr={100,100};DispResult(arr);}catch(IllegalArgumentExceptione){System.err.println("secondexception");}catch(Exceptione){System.err.println("thirdexception");}}}Whatistheresult?A)0DoneB)FirstExceptionDoneC)SecondExceptionD)DoneThirdExceptionE)ThirdException答案:E解析:[單選題]37.Given:AbstractclassA1{Publicabstractvoidm1();Publicvoidm2(){System.out.println("Green");}}AbstractclassA2extendsA1{Publicabstractvoidm3();Publicvoidm1(){System.out.println("Cyan");}Publicvoidm2(){System.out.println("Blue");}}PublicclassA3extendsA2{Publicvoidm1(){System.out.println("Yellow");}Publicvoidm2(){System.out.println("Pink");}Publicvoidm3(){System.out.println("Red");}Publicstaticvoidmain(String[]args){A2tp=newA3();Tp.m1();Tp.m2();Tp.m3();}}Whatistheresult?A)YellowPinkRedB)CyanBlueRedC)CyanGreenRedD)CompilationFails答案:A解析:[單選題]38.Given:ClassA{publicA(){System.out.print("A");}}ClassBextendsA{publicB(){//linen1System.out.print("B");}}ClassCextendsB{publicC(){//linen2System.out.print("C");}publicstaticvoidmain(String[]args){Cc=newC();}}Whatistheresult?A)CBAB)CC)ABCD)Compilationfailsatlinen1andlinen2答案:C解析:[單選題]39.Given:PublicclassProduct{intid;Stringname;publicProduct(intid,Stringname){this.id=id;=name;}}Andgiventhecodefragment:Productp1=newProduct(101,"pen");Productp2=newProduct(101,"pen");Productp3=p1;Booleanans1=p1==p2;Booleanans2=.equals();System.out.print(ans1+":"+ans2);Whatistheresult?A)true:trueB)true:falseC)false:trueD)false:false答案:C解析:[單選題]40.Given:PublicclassMyFor1{Publicstaticvoidmain(String[]args){Int[]x={6,7,8};For(inti:x){System.out.print(i+??);I++;}}}Whatistheresult?A)678B)789C)012D)6810E)Compilationfails答案:A解析:[單選題]41.Given:PublicclassTest{Publicstaticvoidmain(String[]args){Intax=10,az=30;Intaw=1,ay=1;Try{Aw=ax%2;Ay=az/aw;}Catch(ArithmeticExceptione1){System.out.println("InvalidDivisor");}Catch(Exceptione2){Aw=1;System.out.println("DivisorChanged");}Ay=az/aw;//Line14System.out.println("SuccesfulDivision"+ay);}}Whatistheresult?A)InvalidDivisorDivisorChangedSuccessfulDivision30B)InvalidDivisorSuccessfulDivision30C)InvalidDivisorExceptioninthread"main"java.lang.ArithmeticException:/byzeroattest.Teagle.main(Teagle.java:14)D)InvalidDivisorExceptioninthread"main"java.lang.ArithmeticException:/byzeroattest.Teagle.main(Teagle.java:14)SuccessfulDivision1答案:C解析:[單選題]42.Giventhecodefragment:StringBuildersb1=newStringBuilder(?Duke?);Stringstr1=sb1.toString();//insertcodeheresystem.out.print(str1==str2);Whichcodefragment,wheninsertedatline9,enablesthecodetoprinttrue?A)Stringstr2=str1;B)Stringstr2=newString(str1);C)Stringstr2=sb1.toString();D)Stringstr2="Duke";答案:A解析:[單選題]43.Giventhefollowingcode:Int[]intArr={15,30,45,60,75};IntArr[2]=intArr[4];IntArr[4]=90;WhatarethevaluesofeachelementinintArrafterthiscodehasexecuted?A)15,60,45,90,75B)15,90,45,90,75C)15,30,75,60,90D)15,30,90,60,90E)15,4,45,60,90答案:C解析:[單選題]44.Given:ClassVehicle{intx;Vehicle(){this(10);//linen1}Vehicle(intx){this.x=x;}}ClassCarextendsVehicle{inty;Car(){super();this(20);//linen2}Car(inty){this.y=y;}publicStringtoString(){returnsuper.x+":"+this.y;}}Andgiventhecodefragment:Andgiventhecodefragment:Vehicley=newCar();System.out.println(y);Whatistheresult?A)10:20B)0:20C)Compilationfailsatlinen1D)Compilationfailsatlinen2答案:D解析:[單選題]45.Given:publicclassTestField{intx;inty;publicvoiddoStuff(intx,inty){this.x=x;y=this.y;}publicvoiddisplay(){System.out.print(x+""+y+":");}publicstaticvoidmain(String[]args){TestFieldm1=newTestField();m1.x=100;m1.y=200;TestFieldm2=newTestField();m2.doStuff(m1.x,m1.y);m1.display();m2.display();}}Whatistheresult?A)100200:100200B)1000:1000:C)100200:1000:D)1000:100200:答案:C解析:[單選題]46.Given:PublicclassApp{StringmyStr="7007";PublicvoiddoStuff(Stringstr){IntmyNum=0;Try{StringmyStr=str;MyNum=Integer.parseInt(myStr);}catch(NumberFormatExceptionne){System.err.println("Error");}System.out.println("myStr:"+myStr+",myNum:"+myNum);}Publicstaticvoidmian(String[]args){Appobj=newApp();Obj.doStuff("9009");}}Whatistheresult?A)myStr:9009,myNum:9009B)myStr:7007,myNum:7007C)myStr:7007,myNum:9009D)Compilationfails答案:C解析:[單選題]47.Given:publicclassWhizlabs{Publicstaticvoidmain(String[]args){StringBuildersb=newStringBuilder("1Z0");Sb.concat("-808");System.out.println(sb);}}Whatistheoutput?A)1Z0B)1Z0-808C)Anexceptionwillbethrown.D)Compilationfailstoerroratline3E)Compilationfailstoerroratline4答案:E解析:[單選題]48.Giventhecodefragment:inta=-10;Intb=17;Intc=expression1;Intd=expression2;C++;D--;System.out.println(c+","+d);Whatcouldexpression1andexpression2be,respectively,inordertoproduceoutput-8,16?A)++a,--bB)++a,b--C)A++,--bD)A++,b--答案:B解析:[單選題]49.Given:ClassX{PublicvoidmX(){System.out.println("Xm1");}}ClassYextendsX{PublicvoidmX(){System.out.println("Xm2");}PublicvoidmY(){System.out.println("Ym");}}PublicclassTest{Publicstaticvoidmain(String[]args){Xxref=newY();//向上轉(zhuǎn)型Yyref=(Y)xref;//向下轉(zhuǎn)型Yref.mY();//向下轉(zhuǎn)型后,可調(diào)用子類獨(dú)有的方法Xref.mx();//向上轉(zhuǎn)型后的父類變量,調(diào)用子類重寫父類的方法,}但不能調(diào)用子類的有的方法和屬性}A)YmXm2B)YmXm1C)CompilationfailsD)AClassCastExceptionisthrownatruntime答案:A解析:[單選題]50.Given:ClassAlpha{Intns;Staticints;Alpha(intns){If(s<ns){S=ns;This.ns=ns;}}VoiddoPrint(){System.out.println("ns="+ns+"s="+s);}}PublicclassTestA{Publicstaticvoidmain(String[]args){Alpharef1=newAlpha(50);Alpharef2=newAlpha(125);Alpharef3=newAlpha(100);Ref1.doPrint();Ref2.doPrint();Ref3.doPrint();}}Whatisthisresult?A)ns=50s=125ns=125s=125ns=100s=125B)ns=50s=125ns=125s=125ns=0s=125C)ns=50s=125ns=125s=125ns=100s=100D)ns=50s=125ns=125s=125ns=0s=125答案:B解析:[單選題]51.Publicstaticvoidmain(String[]args){String[][]arr={{"A","B","C"},{"D","E"}};for(inti=0;i<arr.length;i++){for(intj=0;j<arr[i].length;j++){System.out.println(arr[i][j])+"");if(arr[i][j]).equals("B")){break;}}continue;}}A)ABCB)ABCDEC)ABDED)Complilatonfails.答案:C解析:[單選題]52.Giventhecodefragment:StringBuildersb1=newStringBuilder(?Duke?);Stringstr1=sb1.toString();//insertcodehereSystem.out.print(str1==str2);Whichcodefragment,wheninsertedatline9,enablesthecodetoprinttrue?A)Stringstr2=str1;B)Stringstr2=newString(str1);C)Stringstr2=sb1.toString();D)Stringstr2="Duke";答案:A解析:[單選題]53.93.Given:PublicclassFieldInit{charc;booleanb;floatf;voidprintAll(){System.out.println("c="+c);System.out.println("c="+b);System.out.println("c="+f);}publicstaticvoidmain(String[]args){FieldInitf=newFieldInit();f.printAll();}}A)c=nullb=falsef=0.0FB)c=0b=falsef=0.0fC)c=nullb=truef=0.0D)c=b=falsef=0.0答案:D解析:[單選題]54.Whichofthefollowingcanfillintheblankinthiscodetomakeitcompile?PublicclassExam{voidmethod(){}[21]}PublicclassOCAJPextendsExam{____voidmethod(){}}A)abstractB)final[22]C)privateD)defaultE)int答案:B解析:[單選題]55.intx=100;Inta=x++;//式子的值與x本身的值的區(qū)別Intb=++x;Intc=x++;Intd=(a<b)?(a<c)?a:(b<c)?b:c;System.out.println(d);Whatistheresult?A)100B)101C)102D)103E)Compilationfails答案:E解析:[單選題]56.classX{intx1,x2,x3;}ClassYextendsX{inty1;Y(){x1=1;x2=2;y1=10;}}ClassZextendsY{Intz1;Z(){x1=3;y1=20;z1=100;}}And,PublicclassTest3{publicstaticvoidmain(String[]args){zobj=newZ();System.out.println(obj.x3+","+obj.y1+","+obj.z1);}}Whichconstructorinitializesthevariablex3?A)OnlythedefaultconstructorofclassXB)Onlytheno-argumentconstructorofclassYC)Onlytheno-argumentconstructorofclassZD)Onlythedefaultconstructorofobjectclass答案:A解析:[單選題]57.PublicclassMsg{publicstaticStringdoMsg(charx){return"GoodDay!";}publicstaticStringdoMsg(inty){return"GoodLuck!";}publicstaticvoidmain(String[]args){charx=8;intz='8';System.out.println(doMsg(x));System.out.print(doMsg(z));}}Whatistheresult?A)GoodDay!GoodLuck!B)GoodDay!GoodDay!C)GoodLuck!GoodDay!D)GoodLuck!GoodLuck!E)Compilationfails答案:A解析:[單選題]58.Giventhecodefragment:Publicstaticvoidmain(String[]args){ArrayListmyList=newArrayList();String[]myArray;try{while(true){myList.add("MyString");}}catch(RuntimeExceptionre){System.out.println("CaughtaRuntimeException");}catch(Exceptione){System.out.println("CaughtanException");}System.out.println("Readytouse");}Whatistheresult?A)Executionterminatesinthefirstcatchstatement,andcaughtaRuntimeExceptionisprintedtotheconsole.B)ExecutionterminatesInthesecondcatchstatement,andcaughtanExceptionisprintedtotheconsole.C)Aruntimeerroristhrowninthethread"main".D)Executioncompletesnormally,andReadytous?isprintedtotheconsole.E)Thecodefailstocompilebecauseathrowskeywordisrequired.答案:C解析:拋出:java.lang.OutOfMemoryError:Javaheapspace[單選題]59.Given:ClassProduct{doubleprice:}PublicclassTest{punlicvoidupdatePrice(Productproduct,doubleprice){price=price*2;product.price=produc
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- GH/T 1430-2023農(nóng)民專業(yè)合作社信用信息數(shù)據(jù)元
- 《汽車結(jié)構(gòu)認(rèn)識(shí)》課件
- 單位管理制度合并選集【職員管理】十篇
- 單位管理制度范例選集職工管理十篇
- 單位管理制度呈現(xiàn)合集職工管理十篇
- 單位管理制度呈現(xiàn)大合集員工管理
- 《店鋪運(yùn)營(yíng)管理》課件
- 《生藥分析1》課程實(shí)施大綱
- 某科技園物業(yè)管理方案
- 2024年供電公司安全稽查總結(jié)
- 錨桿框格梁施工技術(shù)交底
- 深圳分區(qū)地圖可移動(dòng)編輯
- 2023年新版烏斯特統(tǒng)計(jì)公報(bào)即將發(fā)布
- 污水處理廠安全生產(chǎn)風(fēng)險(xiǎn)分級(jí)管控體系方案全套資料匯編完整版
- 人教部編版三年級(jí)語(yǔ)文上冊(cè)古詩(shī)詞日積月累默寫模板
- 高危急性胸痛的快速診斷和誤診病案分析
- (完整版)綜合醫(yī)院康復(fù)醫(yī)學(xué)科建設(shè)與管理指南
- GB/T 41649-2022木制玩具中甲醛釋放量的測(cè)定燒瓶法
- JJF 1384-2012開口/閉口閃點(diǎn)測(cè)定儀校準(zhǔn)規(guī)范
- GB/T 33720-2017LED照明產(chǎn)品光通量衰減加速試驗(yàn)方法
- 教師政治紀(jì)律方面存在的問(wèn)題及整改措施集合5篇 教師政治紀(jì)律方面存在的問(wèn)題及整改措施怎么寫
評(píng)論
0/150
提交評(píng)論