Java试题及答案英文版doc.docx
《Java试题及答案英文版doc.docx》由会员分享,可在线阅读,更多相关《Java试题及答案英文版doc.docx(32页珍藏版)》请在冰豆网上搜索。
Java试题及答案英文版doc
1・Whichtwodemonstrateanuisa”relationship?
(ChooseTwo)
A.publicinterfacePerson{}
publicclassEmployeeextendsPerson{}
B.publicinterfaceShape{}
publicclassEmployeeextendsShape{}
C.publicinterfaceColor{}
publicclassEmployeeextendsColor{}
D.publicclassSpecies{}
publicclassAnimal{privateSpeciesspecies;}
E.interfaceComporient{}
ClassContainerimplementsComponent(
PrivateComponent[]children;
Answer:
de
2.Given:
1.packagefoo;
2.
2.publicclassOuter(
3.publicstaticclassInner(
4.)
5.)
Whichstatementistrue?
A.AninstanceoftheInnerclasscanbeconstructedwith“newOuter」nner()”
B.Aninstanceoftheinnerclasscannotbeconstructedoutsideofpackagefoo
C.Aninstanceoftheinnerclasscanonlybeconstructedfromwithintheouterclass
D.Fromwithinthepackagebar,aninstaneeoftheinnerclasscanbeconstructedwith“newinner()n
Answer:
c
3.Exhibit:
1publicclassenclosinggone{
2publicclassinsideone{}
3}
4publicclassinertest{
5publicstaticvoidmain(Stringf]args){
6enclosingoneeo=newenclosingone();
7//insertcodehere
8}
}
Whichstatementatline7constructsaninstanceoftheinnerclass?
A.InsideOneei=eo.newlnsideOne();
B.B.Eo」nsideOneei=eo.newInsideOne();
CInsideOneei=EnclosingOne.newInsideOne();
D.EnclosingOneInsideOneei=eo.newlnsideOne();
Answer:
a
C.4.
D.1)classSuper{
E.2)publicfloatgetNum(){return3.Of;}
F・3)}
G.4)
H.5)publicclassSubextendsSuper{
I.6)
J・7)}
K.whichmethod,placedatline6,willcauseacompilererror?
L.A.publicfloatgetNum(){return4.Of;}
M.B.publicvoidgetNum(){}
N.C.publicvoidgetNum(doubled){}
O.D.publicdoublegetNum(floatd){return4.0d;}
Answer:
B
5.
1)publicclassFoo{
2)publicstaticvoidmain(Stringargs[]){
3)try{return;}
4)finally!
System.out.println(^^Finally,,);}
5)}
6)}
whatistheresult?
A.Theprogramrunsandprintsnothing.
B.Theprogramrunsandprints“Finally”.
C.Thecodecompiles,butanexceptionisthrownatruntime・
D.Thecodewillnotcompilebecausethecatchblockismissing.
Answer:
b
6・
//pointX
publicclassFoo{
publicstaticvoidmain(String[]args){
PrintWriterout=newPrintWriter(new
java.io.OutputStreamWriter(System.out),true);
out.println(,,HelloH);
}
}
whichstatementatpointXonline1allowsthiscodetocompileandrun?
A.importjava.io.PrintWriterB.ineludejava.io.Printwriter
C.importjava.io.OutputStreamWriterD.includejava.io.OutputStreamWriter
E.Nostatementisneeded
Answer:
a
6.whichthreearevaliddeclaractionofafloat?
A.floatfoo=-1;
B.floatfoo=1.0;
C.floatfoo=42e1;
D.floatfoo=2.02f;
E.floatfoo=3.03d;
F.floatfoo=0x0123;
Answer:
adf
8.
intindex=1;
intfoo[]=newint[3];
intbar=foo[index];
intbaz=bar+index;
whatistheresult?
A.bazhasavalueof0
B.bazhasvalueof1
C.bazhasvalueof2
D.anexceptionisthrown
E.thecodewillnotcompile
Answer:
b
9.
1)inti=1,j=10;
2)do{
3)if(i++>-j)continue;19283746
4)}while(i<5);
AfterExecution,whatarethevalueforiandj?
A.i=6j=5
B.i=5j=5
C.i=6j=4
D.i=5j=6
E.i=6j=6
Answer:
d
10.
1)publicclassX{
2)publicObjectm(){
3)Objecto=newFloat(3.14F);
4)Object[]oa=newObject[1];
5)oa[0]=o;
6)o=null;
7)oa[0]=null;
8)System.out.println(oa[0]);
9)}
10)}
whichlineistheearliestpointtheobjectareferedisdefinitelyelibiletobegarbagecollectioned?
A.Afterline4
B.Afterline5
C.Afterline6
D.Afterline7
E.Afterline9
Answer:
d
11.
1.publicclassX{
2.
publicstaticvoidmain(String[]args){
3.
Objecto1=newObject();
4.
Objecto2=o1;
5.
if(o1.equals(o2)){
6.
System.out.println(”Equal”);
7.
}
&
}
9.}
Whatistheresult?
A.Theprogramrunsandprintsnothing.
B.Theprogramrunsandprints“Equal”.
C.Anerroratline5causescompilationtofail.
D.Theprogramrunsbutabortswithanexception.
Answer:
B
12.
1)publicclassTest{
2)publicstaticvoidadd3(lntegeri){
3)intval=i.intValue();
4)val+=3;
5)i=newInteger(val);
6)}
7)publicstaticvoidmain(Stringargs[]){
8)Integeri=newInteger(O);
9)add3(i);
10)System.out.println(i.intValue());
11)}
12)}
whatistheresult?
A.compilefail
B.printoutn0u
C.printoutM3n
D.compilesuccededbutexceptionatline3
Answer:
b
13.
Given:
1.publicclassFoo{
2.publicvoidmain(String[]args){
3.system.out.printlnfHelloWorld.5,);
4.}
5.}
Whatistheresult?
A.Anexceptionisthrown.
B.Thecodedoesnotcompile・
C.“HelloWorld.5,isprintedtotheterminal.
D.Theprogramexitswithoutprintinganything.
AnswerA
14.Given:
13.publicclassFoo{
14.publicstaticvoidmain(String[]args){
15.StringBuffera=newStringBuffer(“A”);
16.StringBufferb=newStringBuffer(“B”);
17.operate(a,b);
18.system.out.println{a+“,”+b};
19.)
20.staticvoidoperate(StringBufferx,StringBuffery){
21.y.append(x);
22.y=x;
23.)
24.}
Whatistheresult?
A.Thecodecompilesandprints
B.Thecodecompilesandprints“A,BA”.
C.Thecodecompilesandprints“AB,B”.
D.Thecodecompilesandprints“AB,AB”.
E.Thecodecompilesandprints“BA,BA”.
F.Thecodedoesnotcompilebecause“+”cannotbeoverloadedforstringBuffer.
AnswerB
15.
Given:
1・publicclassSyncTest{
2.privateintx;
3.privateinty;
4.publicsynchronizedvoidsetX(inti)(x=1;)
5.publicsynchronizedvoidsetY(inti)(y=1;)
6.publicsynchronizedvoidsetXY(int1)(setX(i);setY(i);)
7.publicsynchronizedBooleancheck()(returnx!
=y;)
8.)
Underwhichconditionswillcheck()returntruewhencalledfromadifferentclass?
A.Check()canneverreturntrue・
B.Check()canreturntruewhensetXYiscalledbymultiplethreads.
C.Check()canreturntruewhenmultiplethreadscallsetXandsetYseparately.
D.Check()canonlyreturntrueifSyncTestischangedtoallowxandytobesetseparately.
Answer:
A
16.
1)publicclassTest{
2)publicstaticvoidmain(String[]args){
3)Stringfoo=args[1];
4)Sringbar=args[2];
5)Stringbaz=args[3];
6)}
7)}
javaTestRedGreenBlue
whatisthevalueofbaz?
A.bazhasvalueof””
B.bazhasvalueofnull
C.bazhasvalueof”Red”
D.bazhasvalueof”Blue”
E.bazhasvalueof”Green”
F.thecodedoesnotcompile
G.theprogramthrowanexception
Answer:
G
17.
1)interfaceFoo{
2)intk=0;
3)}
4)publicclassTestimplementsFoo{
5)publicstaticvoidmain(Stringargs[]){
6)inti;
7)Testtest=newTest();
8)
i=test.k;
9)
i=Test.k;
10)
i=Foo.k;
11)
}
12)}
Whatistheresult?
A.Compilationsucceeds.
B.Anerroratline2causescompilationtofail.
C.Anerroratline9causescompilationtofail.
D.Anerroratline10causescompilationtofail.
E.Anerroratline11causescompilationtofail.Answer:
a
classBaseClass{
privatefloatx=1.Of;
privatefloatgetVar(){returnx;}
}
classSubClassextendsBaseClass{
privatefloatx=2.0f;
//insertcode
}
whataretruetooverridegetVar()?
A.floatgetVar(){
B.publicfloatgetVar(){
C.publicdoublegetVar(){
□.protectedfloatgetVar(){
E.publicfloatgetVar(floatf){
Answer:
a,b,d
19.
Given:
inti=1,j=10;
do{
if(i>j)continue;
卜・;}while(++iv6);
whatarethevaleofiandj?
A.i=6,j=5
B.i=5,j=5
C.i=6,j=4
D.i=5,j=6
E.i=6,j=6
Answer:
A
20・
byte[]arrayl,array2[]
bytearray3[][]
byte[][]array4
ifeachhasbeeninitialized,whichstatementwillcauseacompileerror?
A.array2=arrayl;
B.array2=array3;
C.array2=array4;
D.bothAandB
E.bothAandC
F.bothBandC
Answer:
a
21.
whichfourtypesofobjectscanbethrownuse”throws”?
A.Error
B.Event
C.Object
D.Excption
E.Throwable
F.RuntimeException
Answer:
A,D,E,F
22.
1)publicclassTest{
2)publicstaticvoidmain(String[]args){
3)unsignedbyteb=0;
4)b-;
5)
5)}
6)}
whatisthevalueofbatline5?
A.-1B.255C.127D.compilefailE.compilesucceededbutrunerror
Answer:
d
23.
publicclassExceptionTest{
classTestExceptionextendsException{}
publicvoidrunTest()throwsTestException{}
publicvoidtest()/*pointx*/{
runTest();
}
}
Atpointx,whichcodecanbeaddontomakethecodecompile?
A.throwsException
B.catch(Exceptione)
C.throwsRuntimeException
D.catch(TestExceptione)
E.nocodeisnecessary
Answer:
A
24・
Stringfoo=”blue”;
boolean[]bar=newboolean[1];
if(bar[O]){
foo=HgreenH;
whatisthevalueoffoo?
A.””B.nullC.blueD.green
Answer:
C
25.
whichtwoareequivalent?
A.3/2
B.3<2
C.3*4
D.3«2
E.3*2A2
F.3«<2
Answer:
c,d
26.
intindex=1;
String[]test=newString[3];
Stringfoo=test[index];
whatistheresultoffoo?
A.foohasthevalue“”
B.foohasthevaluenull
C.anexceptionisthrown
D.thecodewillnotcompile
Answer:
b
27.
whichtwoaretrue?
A.staticinnerclassrequiresastaticinitializer
B.Astaticinnerclassrequiresaninstaneeoftheenclosingclass
C.Astaticinnerclasshasnorefereneetoaninstanceoftheenclosingclass
D.Astaticinnerclasshasaccessstothenon・staticmemberoftheotherclass
E.staticmembersofastaticinnerclasscanberefereneedusingtheclassnameofthestaticinnerclass
Answer:
c,e
28.
Youwantsubclassesinanypackagetohaveaccesstomembersofasuperclass.Whichisthemostrestrictiveaccessmodifierthatwillaccomplishthisobjective?
A.Public
B.Private
C.Protected
D.Transient
E.Noaccessmodifierisqualified
Answer:
c
29.Given:
1.abstractclassabstrctlt{
2.abstractfloatgetFloat();
3.)
4.publicclassAbstractTestextendsAbstractly
5.privatefloatf1=1.0f;
6.privatefloatgetFloat(){returnf1:
}
7・}
Whatistheresult?
A.Compilationissuccessful.
B.Anerroronline6causesaruntimefailure.
C.Anerroratline6causescompilationtofail.
D.Anerroratline2causescompilationtofail.
Ans