版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 交通设施养护维修制度
- 2026湖北省定向西北工业大学选调生招录参考题库附答案
- 2026湖南财政经济学院招聘劳务派遣性质工作人员参考题库附答案
- 2026福建泉州市面向北京科技大学选优生选拔引进参考题库附答案
- 2026福建省面向华中师范大学选调生选拔工作考试备考题库附答案
- 2026福建福州第十九中学招聘编外行政人员(劳务派遣)1人考试备考题库附答案
- 2026西藏林芝市察隅县农村公益电影放映人员招聘1人备考题库附答案
- 2026辽宁大连产业园社招招聘备考题库附答案
- 2026陕西省面向南开大学招录选调生备考题库附答案
- 2026鲁南技师学院第一批招聘教师8人参考题库附答案
- GM-T 0130-2023 基于SM2算法的无证书及隐式证书公钥机制
- 美术教师季度考核总结
- GB/T 4074.2-2024绕组线试验方法第2部分:尺寸测量
- 液氨储罐区安全评价
- 生物必修一-高中生物课件
- 慢性肾脏病课件
- TOC制约法纵览高德拉特企管公司
- 配电网工程施工方案模板
- 港口集装箱运输AGV项目规划设计方案
- YY/T 1919-2023超声造影成像性能试验方法
- 国际私法(鲁东大学)智慧树知到课后章节答案2023年下鲁东大学
评论
0/150
提交评论