計算機考試之java面試題庫_第1頁
計算機考試之java面試題庫_第2頁
計算機考試之java面試題庫_第3頁
計算機考試之java面試題庫_第4頁
計算機考試之java面試題庫_第5頁
已閱讀5頁,還剩138頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

JAVA基礎部分面試題庫

第一部分:選擇題

1)哪個不是面向對象的特征()

a)封裝性b)繼承性c)多態性d)健壯性

2)編譯JAVA文件的命令是()o

a)Javab)Javacc)Javadbd)Javaw

3)JAVA源文件的擴展名是()o

a)Classb)exec)javad)dll

4)JAVA內部使用的編碼格式是()。

a)UTF-8b)ASCIIc)UNICODEd)ISO8859-1

5)下列變量名稱不合法的是()

a)Indexb)$bc3&c)_cccded)34#bc5

6)下邊對基本數據類型的說明正確的是()

a)Int可以自動轉換為BYTE類型

b)DOUBLE類型的數據占用2個字節

c)JAVA中一共有4類8種基本數據類型

d)JAVA中一共有3類8種基本數據類型

7)下列不是JAVA關鍵字的是()

a)gotob)ifc)countd)private

8)下列變量聲明中正確的是()

a)Floatf=3.13b)Booleanb=0

c)Intnumber=5d)IntxBytea=x

9)publicvoidgo(){

Stringo二心;

z:

for(intx=0;x<3;x++){

for(inty=0;y<2;y++){

if(x==l)break;

if(x==2&&y==l)breakz;

o=o+x+y;

)

)

System.out.println(o);

)

程序的執行結果是()

a)00

b)0001

c)000120

d)00012021

e)Compilationfails.

f)Anexceptionisthrownatruntime

10)classPayload{

privateintweight;

publicPayload(intw){weight=w;}

publicvoidsetWeight(intw){weight=w;}

publicStringtoStringO{returnInteger.toString(weight);}

)

publicclassTestPayload{

staticvoidchangePayload(Payloadp){/*insertcode*/}

publicstaticvoidmain(String[]args){

Payloadp=newPayload(200);

p.setWeight(1024);

changePayload(p);

System.out.println(npis”+p);

}

)

Insertcode處寫入哪句話,可以使程序的輸出結果是420()

a)p.setWeight(420);

b)p.changePay!oad(420);

c)p=newPayload(420);

d)Payload.setWeight(420);

e)p=Payload.setWeight(420);

11)voidwaitForSignal(){

Objectobj=newObjectQ;

synchronized(Thread.currentThreadO){

obj.wait();

obj.notify();

)

}這個程序片段的運行結果是什么()

a)ThiscodecanthrowanInterruptedException.

b)ThiscodecanthrowanIllegalMonitorStateException.

c)ThiscodecanthrowaTimeoutExceptionaftertenminutes.

d)Reversingtheorderofobj.wait()andobj.notifyOmightcausethismethodtocomplete

normally.

12)publicclassThreads2implementsRunnable{

publicvoidrun(){

System.out.println(nrun.H);

thrownewRuntimeException('^Problem^^);

)

publicstaticvoidmain(String[]args){

Threadt=newThread(newThreads2());

t.start();

System.out.println(nEndofmethod.");

運行結果是什么,請選擇2個()

a)java.lang.RuntimeException:Problem

b)run.java.lang.RuntimeException:Problem

c)Endofmethod.java.lang.RuntimeException:Problem

d)Endofmethod,run.java.Iang.RuntimeException:Problem

e)run.java.lang.RuntimeException:ProblemEndofmethod.

13)下邊哪2句話的描述是正確的()

a)Itispossibleformorethantwothreadstodeadlockatonce

b)TheJVMimplementationguaranteesthatmultiplethreadscannotenterintoadeadlocked

state.

c)Deadlockedthreadsreleaseoncetheirsleep()method'ssleepdurationhasexpired.

d)Deadlockingcanoccuronlywhenthewait(),notify(),andnotifyAll()methodsareused

incorrectly.

e)Itispossibleforasingle-threadedapplicationtodeadlockifsynchronizedblocksareused

incorrectly.

f)fapieceofcodeiscapableofdeadlocking,youcannoteliminatethepossibilityof

deadlockingbyinsertinginvocationsofThread.yield().

14)publicclassThreads!implementsRunnable{

publicvoidrun(){

System.out.println("run.n);

thrownewRuntimeException(nProblemn);

}

publicstaticvoidmain(String[]args){

Threadt=newThread(newThreads2());

t.start();

System.out.println(nEndofmethod.");

)

}程序運行結果是,選擇2個()

a)java.lang.RuntimeException:Problem

b)run.java.lang.RuntimeException:ProblemEndofmethod

c)Endofmethod.java.lang.RuntimeException:Problem

d)Endofmethod,run.java.lang.RuntimeException:Problem

15)voidwaitForSignal(){

Objectobj=newObject();

synchronized(Thread.currentThread()){

obj.wait();

obj.notifyO;

)

}下列那句描述是正確的()

a)ThiscodecanthrowanInterruptedException.

b)ThiscodecanthrowanIllegalMonitorStateException.

c)ThiscodecanthrowaTimeoutExceptionaftertenminutes.

d)ThiscodedoesNOTcompileunlessnobj.wait()nisreplacedwith"((Thread)obj).wait()n.

16)11.classPingPong2{

synchronizedvoidhit(longn){

for(inti=1;i<3;i++)

System.out.print(n++i+””);

)

}

publicclassTesterimplementsRunnable{

staticPingPong2pp2=newPingPong2();

publicstaticvoidmain(String[]args){

newThread(newTester()).start();

newThread(newTester()).start();

.publicvoidrun(){pp2.hit(Thread.currentThread().getId());}

}運行結果是()

a)Theoutputcouldbe5-16-16-25-2

b)Theoutputcouldbe6-16-25-15-2

c)Theoutputcouldbe6-15-26-25-1

d)Theoutputcouldbe6-16-25-17-1

17)1.publicclassThreads4{

publicstaticvoidmain(String[]args){

newThreads4().go();

)

publicvoidgo(){

Runnabler=newRunnable(){

publicvoidrun(){System.out.print(”foo");

)

);

Threadt=newThread(r);

t.start();

t.startQ;

}運行結果是()

a)Compilationfails.

b)Anexceptionisthrownatruntime.

c)Thecodeexecutesnormallyandprints"foon.

d)Thecodeexecutesnormally,butnothingisprinted.

18)11.publicclassBarn{

publicstaticvoidmain(String[]args){

newBam().go(”hi”,1);

newBarn().go(”hi”,“world”,2);

)

publicvoidgo(String...y,intx){

System.out.print(y[y.length-1]+”

)

}運行結果是()

a)hihi

b)hiworld

c)Compilationfails

d)Anexceptionisthrownatruntime.

19)10.classNav{

.publicenumDirection{NORTH,SOUTH,EAST,WEST}

)

publicclassSprite{

//insertcodehere

}哪句代碼放到14行,程序可以正常編譯()

a)Directiond=NORTH;

b)Nav.Directiond=NORTH;

c)Directiond=Direction.NORTH;

d)Nav.Directiond=Nav.Direction.NORTH;

20)11.publicclassRainbow{

publicenumMyColor{

RED(OxffOOOO),GREEN(OxOOffOO),BLUE(OxOOOOff);

privatefinalintrgb;

MyColor(intrgb){this.rgb=rgb;}

publicintgetRGB(){returnrgb;}

);

publicstaticvoidmain(String[]args){

//insertcodehere

)

}哪句代碼放到19行,程序可以正常編譯()

a)MyColorskyColor=BLUE;

b)MyColortreeColor=MyColor.GREEN;

c)Compilationfailsduetoothererror(s)inthecode.

d)MyColorpurple=MyColor.BLUE+MyColor.RED;

21)5.classAtom{

Atom(){System.out.print(natom”);}

)

classRockextendsAtom{

Rock(Stringtype){System.out.print(type);}

}■■

publicclassMountainextendsRock{

Mountain(){

super(Mgranite");

newRock("granite");

}

publicstaticvoidmain(String[]a){newMountain();}

}運行結果是()

a)Compilationfails

b)atomgranitegranite

c)Anexceptionisthrownatruntime.

d)atomgraniteatomgranite

22)1.interfaceTestA{StringtoStringO;}

publicclassTest{

publicstaticvoidmain(String[]args){

4System.out.println(newTestA(){

publicStringtoStringO{return"test";}

));

}運行結果是()

a)test

b)null

c)Anexceptionisthrownatruntime.

d)Compilationfailsbecauseofanerrorinline1.

23)11.publicstaticvoidparse(Stringstr){

try{

floatf=Float.parseFloat(str);

}catch(NumberFormatExceptionnfe){

f=0;}finally{

17.System.out.println(f);

publicstaticvoidmain(String[]args){

parseC4nvalid'1);

}運行結果是()

a)0.0

b)Compilationfails.

c)AParseExceptionisthrownbytheparsemethodatruntime

d)ANumberFormatExceptionisthrownbytheparsemethodatruntime

24)1.publicclassBlip{

protectedintblipvert(intx){return0;}

)

classVertextendsBlip{

//insertcodehere

}下列哪5個方法放到代碼第五行,可以讓程序編譯正確,選擇5個()

a)publicintblipvert(intx){return0;}

b)privateintblipvert(intx){return0;}

c)privateintblipvert(longx){return0;}

d)protectedlongblipvert(intx){return0;}

e)protectedintblipvert(longx){return0;}

f)protectedlongblipvert(longx){return0;}

g)protectedlongblipvert(intx,inty){return0;}

25)1.classSuper{

privateinta;

protectedSuper(inta){this.a=a;}

}...

classSubextendsSuper{

publicSub(inta){super(a);}

publicSub(){this.a=5;}

}下列哪2條語句是正確的()

a)Changeline2to:publicinta;

b)Changeline2to:protectedinta;

c)Changeline13to:publicSub(){this(5);}

d)Changeline13to:publicSub(){super(5);}

e)Changeline13to:publicSub(){super(a);}

26)packagetest;

classTarget{

publicStringname="hello”;

}如果可以直接修改和訪問name這個變量,下列哪句話是正確的()

a)anyclass

b)onlytheTargetclass

c)anyclassinthetestpackage

d)anyclassthatextendsTarget

27)11.abstractclassVehicle{publicintspeed(){return0;}

classCarextendsVehicle{publicintspeed(){return60;}

classRaceCarextendsCar{publicintspeed(){return150;}...

RaceCarracer=newRaceCar();

Carcar=newRaceCar();

Vehiclevehicle=newRaceCarQ;

System.out.println(racer.speed()+"+car.speed()

+*”+vehicle.speed。);運行結果是()

a)0,0,0

b)150,60,0

c)Compilationfails

d)150,150,150

e)Anexceptionisthrownatruntime

28)5.classBuilding{}

publicclassBarnextendsBuilding{

publicstaticvoidmain(String[]args){

Buildingbuild1=newBuildingO;

Barnbaml=newBarn();

Barnbam2=(Bam)build1;

Objectobjl=(Object)build1;

Stringstrl=(String)build1;

Buildingbuild2=(Building)baml;

}15.}運行結果是()

a)Ifline10isremoved,thecompilationsucceeds.

b)Ifline11isremoved,thecompilationsucceeds

c)Ifline12isremoved,thecompilationsucceeds.

d)Ifline13isremoved,thecompilationsucceeds.

e)Morethanonelinemustberemovedforcompilationtosucceed.

29)29.Given:

classMoney{

privateStringcountry="Canada*1;

publicStringgetC(){returncountry;}

)

classYenextendsMoney{

publicStringgetC(){returnsuper.country;}

),

publicclassEuroextendsMoney{

publicStringgetC(intx){returnsuper.getC();}

publicstaticvoidmain(String[]args){

System.out.print(newYen().getC()+””+newEuro().getC());

}33.}運行結果是()

a)Canada

b)nullCanada

c)Canadanull

d)Compilationfailsduetoanerroronline26

e)Compilationfailsduetoanerroronline29

30)13.importjava.io.*;

classFoodimplementsSerializable{intgood=3;}

classFruitextendsFood{intjuice=5;)

publicclassBananaextendsFruit{

intyellow=4;

publicstaticvoidmain(String[]args){

Bananab=newBanana();Bananab2=newBanana();

b.serializeBanana(b);//assumecorrectserialization

b2=b.deserializeBanana();//assumecorrect

System.out.printlnC^restore"+b2.yellow+b2.juice+b2.good);

)

//moreBananamethodsgohere

}運行結果是()

a)restore400

b)restore403

c)restore453

d)Compilationfails.

e)Anexceptionisthrownatruntime.

31)11.doubleinput=314159.26;

NumberFormatnf=NumberFormat.getlnstance(Locale.ITALIAN);

Stringb;

//insertcodehere

下列哪條語句可以設置變量b的值為314.159,26()

a).b=nf.parse(input);

b)b=nf.format(input);

c)b=nf.equals(input);

d)b=nf.parseObject(input);

32)1.publicclassTestStringl{

publicstaticvoidmain(String[]args){

Stringstr="420”;

str+=42;

System.out.print(str);

}7.}輸出結果是()

a)42b)420c)462d)42042

33)22.StringBuildersbl=newStringBuilder(H123n);

Stringsi=123”;

//insertcodehere

System.out.println(sb1+””+si);

下列哪句代碼放到程序的第24行,可以輸出"23abcl23abc”()

a)sbl.append(MabcH);sl.append(nabc");

b)sbl.append(HabcH);s1.concat("abc");

c)sbl.concat(nabcn);sl.append("abc");

d)sbl.concat(nabcn);sl.concat(nabcn);

e)sbl.append(uabcn);si=sl.concat(nabcn);

f)sbl.concat(Mabc,r);si=sl.concat("abcn);

g)sbl.append(nabcn);si=si+sl.concat("abcn);

34)1.publicclassLineUp{

publicstaticvoidmain(String[]args){

doubled=12.345;

//insertcodehere

}

}下列哪句代碼放到程序的第4行,可以輸出I12.3451?()

a)System.out.printf("l%7dl\nn,d);

b)System.out.printf("l%7fl\n,f,d);

c)System.out.printf("l%3.7dl\n",d);

d)System.out.printf(nl%3.7fl\n”,d);

e)System.out.printf(Hl%7.3dl\n",d);

f)System.out.printf(nl%7.3fl\n”,d);

35)11.publicclassTest{

publicstaticvoidmain(String[]args){

intx=5;

booleanbl=true;

booleanb2=false;

if((x==4)&&!b2)

System.out.print(nl");

System.out.print("2");

if((b2=true)&&bl)

System.out.print("3");

)

}程序的輸出結果是()

a)2

b)3

c)12

d)23

e)123

f)Compilationfails.

g)Anexceptionisthrownatruntime.

36)10.interfaceFoo{}

classAlphaimplementsFoo{}

classBetaextendsAlpha{}

classDeltaextendsBeta{

publicstaticvoidmain(String]]args){

Betax=newBeta();

//insertcodehere

}18.)

下列哪句代碼放到第16行,可以導致一java.lang.ClassCastException()

a)Alphaa=x;

b)Foof=(Delta)x;

c)Foof=(Alpha)x;

d)Betab=(Beta)(Alpha)x;

37)22.publicvoidgo(){

Stringo="”;

z:

.for(intx=0;x<3;x++){

for(inty=0;y<2;y++){

if(x==l)break;

if(x==2&&y==l)breakz;

o=o+x+y;

)

)

System.out.println(o);

}當調用g。方法時,輸出結果是什么()

a)00

b)0001

c)000120

d)000120221

38)11.staticvoidtest()throwsRuntimeException{

try(

System.out.print(ntest");

thrownewRuntimeException();

)

catch(Exceptionex){System.out.print("exception");}

)

publicstaticvoidmain(String[]args){

try{test();}

catch(RuntimeExceptionex){System.out.print(nruntime");}

System.out.print(nendn);}程序運行結果是()

a)testend

b)Compilationfails.

c)testruntimeend

d)testexceptionend

e).AThrowableisthrownbymainatruntime

39)33.try{

//somecodehere

}catch(NullPointerExceptionel){

System.out.print(Ha");

}catch(Exceptione2){

System.out.print(,,bn);

}finally{

System.out.print("cH);

}如果程序的第34行會拋出一些異常,程序的運行結果是()

a)ab)bc)cd)ace)abc

40)31.//somecodehere

try(

//somecodehere

}catch(SomeExceptionse){

//somecodehere

}finally{

//somecodehere

}哪種情況下37行的代碼會執行,請選擇3個()

a)Theinstancegetsgarbagecollected.

b)Thecodeonline33throwsanexception.

c)Thecodeonline35throwsanexception.

d)Thecodeonline31throwsanexception.

e)Thecodeonline33executessuccessfully.

41)10.intx=0;

inty=10;

do{

y-;++X;

}while(x<5);

System.out.print(x+"J+y);

程序運行結果是()

a)5,6

b)5,5

c)6,5

d)6,6

42)publicclassDrink{

publicstaticvoidmain(String[largs){

booleanassertsOn=true;

assert(assertsOn):assertsOn=true;

if(assertsOn){

System.owZ.println(nassertison");

}程序運行結果是()

a)nooutput

b)nooutputassertison

c)assertison

d)assertisonAnAssertionErroristhrown.

43)11.Floatpi=newFloat(3.14f);

if(pi>3){

System.out.print(npiisbiggerthan3.");

)

else{System.out.print(npiisnotbiggerthan3.'*);

)…

finally{

System.out.println("Haveaniceday.");

}程序運行結果是()

a)Compilationfails.

b)piisbiggerthan3

c)Anexceptionoccursatruntime.

d)piisbiggerthan3.Haveaniceday.

e)piisnotbiggerthan3.Haveaniceday.

44)1.publicclassBoxer1{

Integeri;

intx;

publicBoxer1(inty){

x=i+y;

System.out.println(x);

)

publicstaticvoidmain(String[]args){

newBoxer1(newInteger(4));

)

}運行結果是()

a)Thevalue"4"isprintedatthecommandline.

b)Compilationfailsbecauseofanerrorinline5.

c)ANullPointerExceptionoccursatruntime.

d)ANumberFormatExceptionoccursatruntime.

45)1.publicclassPerson{

privateStringname;

publicPerson(Stringname){=name;}

publicbooleanequals(Personp){

return.equals();6.}7.}

下列哪條語句是正確的()

a)TheequalsmethoddoesNOTproperlyoverridetheObject.equalsmethod.

b)Compilationfailsbecausetheprivateattributecannotbeaccessedinline5.

c)Toworkcorrectlywithhash-baseddatastructures,thisclassmustalsoimplementthe

hashCodemethod.

d)WhenaddingPersonobjectstoajava.util.Setcollection,theequalsmethodinline4will

preventduplicates.

46)1.publicclassScoreimplementsComparable{

privateintwins,losses;

publicScore(intw,int1){wins=w;losses=1;}

publicintgetWins(){returnwins;}

publicintgetLosses(){returnlosses;}

publicStringtoStringO{

retum+wins+”J+losses+”>”;

}

//insertcodehere

}下列哪句代碼放到第9行,程序可以正確編譯()

a)publicintcompareTo(Objecto){/*morecodehere*/}

b)publicintcompareTo(Scoreother){/*morecodehere*/)

c)publicintcompare(Scoresi,Scores2){/*morecodehere*/}

d)publicintcompare(Objectol,Objecto2){/*morecodehere*/}

47)3.publicclassBatman{

intsquares=81;

publicstaticvoidmain(String[]args){

newBatman().go();

}

voidgo(){

incr(++squares);

System.out.println(squares);

)

voidincr(intsquares){squares+=10;}

}程序運行結果是()

a)81

b)82

c)91

d)92

48)15.publicclassYippee{

publicstaticvoidmain(String[]args){

for(intx=1;x<args.length;x++){

System.out.print(args[x]+"");19.}20.}21.)

在控制臺依次輸入兩條命令

javaYippee

javaYippee1234

程序的運行結果是()

a)Nooutputisproduced.123

b)Nooutputisproduced.234

c)Nooutputisproduced.1234

d)Anexceptionisthrownatruntime.123

e)Anexceptionisthrownatruntime.234

f)Anexceptionisthrownatruntime.1234

49)13.publicclassPass{

publicstaticvoidmain(String[]args){

intx=5;

Passp=newPass();

p.doStuff(x);

System.out.print(nmainx="+x);

)

21.voiddoStuff(intx){

System.out.print(HdoStuffx=n+x++);

)

}程序的運行結果是()

a)Compilationfails.

b)Anexceptionisthrownatruntime.

c)doStuffx=6mainx=6

d)doStuffx=5mainx=5

e)doStuffx=5mainx=6

f)doStuffx=6mainx=5

50)3.interfaceAnimal{voidmakeNoise();}

classHorseimplementsAnimal{

Longweight=1200L;

publicvoidmakeNoise(){System.out.println("whinny");}

)

publicclassIcelandicextendsHorse{

publicvoidmakeNoise(){System.out.println(Hvinnyn);}

publicstaticvoidmain(String[]args){

Icelandicil=newIcelandic();Icelandici2=newIcelandic();

12.Icelandici3=newIcelandic();

i3=il;il=i2;i2=null;i3=il;

)

}程序運行結束后,有幾個對象符合垃圾回收的條件()

a)0

b)1

c)2

d)3

e)4

f)6

51)11.String[]elements={"for","tea","too"};

Stringfirst=(elements.length>0)elements[0]:null;

程序運行結果是()

a)Compilationfails.

b)Anexceptionisthrownatruntime.

c)Thevariablefirstissettonull.

d)Thevariablefirstissettoelements[0].

52)31.classFoo{

publicinta=3;

publicvoidaddFive(){a+=5;System.out.print(nf");}

)

classBarextendsFoo{

publicinta=8;

publicvoidaddFive(){this.a+=5;System.out.print("b");}

)

主方法執行下列語句

Foof=newBar();

f.addFive();

System.out.println(f.a);程序運行結果是()

a)b,3

b)b,8

c)b,13

d)f,3

e)f,8

f)f,13

g)Compilationfails.

h)Anexceptionisthrownatruntime.

53)1.classClassA{

publicintnumberOflnstances;

protectedClassA(intnumberOflnstances){

this.numberOflnstances=numberOflnstances;

)

)

publicclassExtendedAextendsClassA{

privateExtendedA(intnumberOflnstances){

uper(numberOflnstances);

)

publicstaticvoidmain(String[]args){

ExtendedAext=newExtendedA(420);

System.out.print(ext.numberOflnstances);

)

}下列哪句描述是正確的()

a)420istheoutput.

b)Anexceptionisthrownatruntime.

c)Allconstructorsmustbedeclaredpublic

d)ConstructorsCANNOTusetheprivatemodifier.

e)ConstructorsCANNOTusetheprotectedmodifier.

54)11.classClassA{}

classClassBextendsClassA{}

classClassCextendsClassA{}

and:

ClassApO=newClassAQ;

ClassBpl=newClassB();

ClassCp2=newClassC();

ClassAp3=newClassB();

ClassAp4=newClassC();

下邊哪句代碼是正確的,請選擇3個()

a)pO=pl;

b)pl=p2;

c)p2=p4;

d)p2=(ClassC)pl;

e)pl=(ClassB)p3;

f)p2=(ClassC)p4;

55)5.classThingy{Meterm=newMeter();}

classComponent{voidgo(){System.out.print(',cn);}}

classMeterextendsComponent{voidgo(){System.out.print(nmH);}}

9.classDeluxeThingyextendsThingy{

publicstaticvoidmain(String[]args){

DeluxeThingydt=newDeluxeThingyO;

dt.m.goO;

Thingyt=newDeluxeThingyO;

t.m.go();

)

}下邊哪句描述是正確的,請選擇2個()

a)Theoutputismm.

b)Theoutputisme.

c)Componentis-aMeter.

d)Componenthas-aMeter.

e)DeluxeThingyis-aComponent.

f)DeluxeThingyhas-aComponent.

56)10.interfaceJumper{publicvoidjump();}...

classAnimal{}...

classDogextendsAnimal{

Tailtail;

}??.

classBeagleextendsDogimplementsJumper{

publicvoidjump(){}

}...

classCatimplementsJumper{

publicvoidjump(){}

}下邊哪句描述是正確的,請選擇3個()

a)Catis-aAnimal

b)Catis-aJumper

c)Dogis-aAnimal

d)Dogis-aJumper

e)Cathas-aAnimal

f)Beaglehas-aTail

g)Beaglehas-aJumper

57)1.importjava.util.*;

publicclassWrappedString{

privateStrings;

publicWrappedString(Strings){this.s=s;}

publicstaticvoidmain(String[]args){

HashSeths=newHashSet();

WrappedStringwsl=newWrappedStringC^ardvark1');

WrappedStringws2=newWrappedString(HaardvarkH);

Stringsi=newStringCaardvark11);

Strings2=newString("aardvarkn);

hs.add(wsl);hs.add(ws2);hs.add(sl);hs.add(s2);

System.out.println(hs.size());}}運行結果是()

a)0

b)1

c)2

d)3

e)4

f)Compilationfails.

d)Anexceptionisthrownatruntime.

58)2.importjava.util.*;

publicclassGetlnLine{

publicstaticvoidmain(String[]args){

PriorityQueuepq=newPriorityQueue();

pq.add("banana");

pq.add("pearn);

pq.addC'apple");

System.out.println(pq.poll()+””+pq.peek());

運行結果是()

a)applepear

b)bananapear

c)appleapple

d)applebanana

59)3.importjava.util.*;

publicclassMapit{

publicstaticvoidmain(String[]args){

Setset=newHashSet();

Integeri1=45;

Integeri2=46;

set.add(il);

set.add(il);

set.add(i2);System.out.print(set.size()+"”);

set.remove(il);System.out.print(set.size()+"

i2=47;

set.remove(i2);System.out.print(set.size()+"");

}16.}程序運行結果是()

a)210

b)211

c)321

d)322

60)12.importjava.util.*;

publicclassExplorer1{

publicstaticvoidmain(String[]args){

TreeSets=newTreeSet();

TreeSetsubs=newTreeSet();

for(inti=606;i<613;i++)

if(i%2==0)s.add(i);

subs=(TreeSet)s.subSet(608,true,611,true);

.s.add(609);

System.out.println(s+"“+subs);

}23.}運行結果是()

a)Compilationfails.

b)Anexceptionisthrownatruntime.

c)[608,609,610,612][608,610]

d)[608,609,610,612][608,609,610]

e)[606,608,609,610,612][608,610]

f)[606,608,609,610,612][608,609,610]

61)3.importjava.util.*;

publicclassQuest{

publicstaticvoidmain(String[]args){

String[]colors={"blue","red","green","yellow","orange"};

Arrays.sort(colors);

ints2=Arrays.binarySearch(colors,norange");

ints3=Arrays.binarySearch(colors,"violet");

System.out.println(s2+""+s3);

}12.}運行結果是()

a)2-1

b)2-4

c)2-5

d)3-1

e)3-4

f)3-5

g)Compilationfails.

h)Anexceptionisthrownatruntime

62)34.HashMapprops=newHashMapO;

props.put("key45","somevalue");

props.put("keyl2","someothervalue");

props.put("key39","yetanothervalue");

.Sets=props.keySet();

//insertcodehere

下列哪行代碼放到39行是正確的()

a)Arrays,sort(s);

b)s=newTreeSet(s);

c)Collections.sort(s);

d)s=newSortedSet(s);

63)1.publicclassTestOneimplementsRunnable{

publicstaticvoidmain(String[]args)throwsException{

Threadt=newThread(newTestOne());

t.start();

System.out.print(',Startedn);

t-join();

System.out.print(HCompleten);

)

publicvoidrun(){

for(inti=0;i<4;i++){

System.out.print(i);

}13.}14.}語系那個結果是()

a)Compilationfails.

b)Anexceptionisthrownatruntime.

c)Thecodeexecutesandprints"StartedComplete*'.

d)Thecodeexecutesandprints"StartedCompleteO123”

e)Thecodeexecutesandprints"Started0123Complete".

64)下邊哪行代碼是正確的,請選擇3個()

a)privatesynchronizedObjecto;

b)voidgo(){synchronized(){/*codehere*/}

c)publicsynchronizedvoidgo(){/*codehere*/}

d)p

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論