JAVA认证 147道SCJP考试试题精解.docx
《JAVA认证 147道SCJP考试试题精解.docx》由会员分享,可在线阅读,更多相关《JAVA认证 147道SCJP考试试题精解.docx(77页珍藏版)》请在冰豆网上搜索。
JAVA认证147道SCJP考试试题精解
JAVA认证:
147道SCJP考试试题精解
LeadingthewayinITtestingandcertificationtools,
QuestionNo:
1
Given:
1.publicclasstest(
2.publicstaticvoidmain(Stringargs[]){
3.inti=0xFFFFFFF1;
4.intj=~i;
5.
6.}
7.)
Whatisthedecimalvalueofjatline5?
A.0
B.1
C.14
D.–15
E.Anerroratline3causescompilationtofail.
F.Anerroratline4causescompilationtofail.
Answer:
C
QuestionNo:
2
Given:
Integeri=newInteger(42);
Long1=newLong(42);
Doubled=newDouble(42.0);
WhichtwoexpressionsevaluatetoTrue?
(ChooseTwo)
A.(i==1)
B.(i==d)
C.(d==1)
D.(i.equals(d))
E.(d.equals(i))
F.(i.equals(42))
Answer:
D,E
QuestionNo:
3
Exhibit:
1.publicclasstest(
2.privatestaticintj=0;
3.
4.privatestaticbooleanmethodB(intk)(
5.j+=k;
6.returntrue;
6.)
7.
8.publicstaticvoidmethodA(inti){
9.booleanb:
10.b=i<10|methodB(4);
11.b=i<10||methodB(8);
12.)
13.
14.publicstaticvoidmain(Stringargs[]}(
15.methodA(0);
16.system.out.printIn(j);
17.)
18.)
Whatistheresult?
A.Theprogramprints“0”
B.Theprogramprints“4”
C.Theprogramprints“8”
D.Theprogramprints“12”
E.Thecodedoesnotcomplete.
Answer:
B
QuestionNo:
4
Given
1.Publicclasstest(
2.Publicstaticvoidmain(Stringargs[])(
3.System.out.printIn(6^3);
4.)
5.)
Whatistheoutput?
Answer:
5
QuestionNo:
5
Given:
1.publicclassFoo{
2.publicstaticvoidmain(String[]args){
3.StringBuffera=newStringBuffer(“A”);
4.StringBufferb=newStringBuffer(“B”);
5.operate(a,b);
6.system.out.printIn{a+“,”+b};
7.)
8.staticvoidoperate(StringBufferx,StringBuffery){
9.x.append{y};
10.y=x;
11.)
12.}
Whatistheresult?
A.Thecodecompilesandprints“A,B”.
B.Thecodecompilesandprints“A,A”.
C.Thecodecompilesandprints“B,B”.
D.Thecodecompilesandprints“AB,B”.
E.Thecodecompilesandprints“AB,AB”.
F.Thecodedoesnotcompilebecause“+”cannotbeoverloadedforStringBuffer.
Answer:
D
QuestionNo:
6
Exhibit:
1.Publicclasstest(
2.PublicstaticvoidstringReplace(Stringtext)(
3.Text=text.replace(‘j',‘i');
4.)
5.
6.publicstaticvoidbufferReplace(StringBuffertext)(
7.text=text.append(“C”)
8.)
9.
10.publicstaticvoidmain(Stringargs[]}(
11.StringtextString=newString(“java”);
12.StringBuffertextBufferString=newStringBuffer(“java”);
13.
14.stringReplace(textString);
15.BufferReplace(textBuffer);
16.
17.System.out.printIn(textString+textBuffer);
18.}
19.)
Whatistheoutput?
Answer:
javajavaC
QuestionNo:
7
Exhibit:
1.publicclasstest{
2.publicstaticvoidadd3(Integeri)}
3.intval=i.intValue();
4.val+=3;
5.i=newInteger(val);
6.}
7.
8.publicstaticvoidmain(Stringargs[]){
9.Integeri=newInteger(0);
10.add3(i);
11.system.out.printIn(i.intValue());
12.}
13.)
Whatistheresult?
A.Compilationwillfail.
B.Theprogramprints“0”.
C.Theprogramprints“3”.
D.Compilationwillsucceedbutanexceptionwillbethrownatline3.
Answer:
B
QuestionNo:
8
Given:
1.publicclassConstOver{
2.publicConstOver(intx,inty,intz){
3.}
4.}
WhichtwooverloadtheConstOverconstructor?
(ChooseTwo)
A.ConstOver(){}
B.ProtectedintConstOver(){}
C.PrivateConstOver(intz,inty,bytex){}
D.PublicObjectConstOver(intx,inty,intz){}
E.PublicvoidConstOver(bytex,bytey,bytez){}
Answer:
A,C
QuestionNo:
9
Given:
1.publicclassMethodOver{
2.publicvoidsetVar(inta,intb,floatc){
3.}
4.}
WhichtwooverloadthesetVarmethod?
(ChooseTwo)
A.PrivatevoidsetVar(inta,floatc,intb){}
B.ProtectedvoidsetVar(inta,intb,floatc){}
C.PublicintsetVar(inta,floatc,intb)(returna;)
D.PublicintsetVar(inta,intb,floatc)(returna;)
E.ProtectedfloatsetVar(inta,intb,floatc)(returnc;)
Answer:
A,C
QuestionNo:
10
Given:
1.classBaseClass{
2.Privatefloatx=1.0f;
3.protectedfloatgetVar()(returnx;)
4.}
5.classSubclassextendsBaseClass(
6.privatefloatx=2.0f;
7.//insertcodehere
8.)
Whichtwoarevalidexamplesofmethodoverriding?
(ChooseTwo)
A.FloatgetVar(){returnx;}
B.PublicfloatgetVar(){returnx;}
C.FloatdoublegetVar(){returnx;}
D.PublicfloatgetVar(){returnx;}
E.PublicfloatgetVar(floatf){returnf;}
Answer:
B,D
QuestionNo:
11
Whichtwodemonstratean“isa”relationship?
(ChooseTwo)
A.publicinterfacePerson{}
publicclassEmployeeextendsPerson{}
B.publicinterfaceShape{}
publicclassEmployeeextendsShape{}
C.publicinterfaceColor{}
publicclassEmployeeextendsColor{}
D.publicclassSpecies{}
publicclassAnimal(privateSpeciesspecies;)
E.interfaceComponent{}
ClassContainerimplementsComponent(
PrivateComponent[]children;
)
Answer:
D,E
QuestionNo:
12
Whichstatementistrue?
A.Ananonymousinnerclassmaybedeclaredasfinal.
B.Ananonymousinnerclasscanbedeclaredasprivate.
C.Ananonymousinnerclasscanimplementmultipleinterfaces.
D.Ananonymousinnerclasscanaccessfinalvariablesinanyenclosingscope.
E.Constructionofaninstanceofastaticinnerclassrequiresaninstanceoftheenclosingouterclass.
Answer:
D
QuestionNo13
Given:
1.packagefoo;
2.
3.publicclassOuter(
4.publicstaticclassInner(
5.)
6.)
Whichstatementistrue?
A.AninstanceoftheInnerclasscanbeconstructedwith“newOuter.Inner()”
B.Aninstanceoftheinnerclasscannotbeconstructedoutsideofpackagefoo.
C.Aninstanceoftheinnerclasscanonlybeconstructedfromwithintheouterclass.
D.Fromwithinthepackagebar,aninstanceoftheinnerclasscanbeconstructedwith“newinner()”
Answer:
A
QuestionNo14
Exhibit:
1.publicclassenclosingone(
2.publicclassinsideone{}
3.)
4.publicclassinertest(
5.publicstaticvoidmain(string[]args)(
6.enclosingoneeo=newenclosingone();
7.//insertcodehere
8.)
9.)
Whichstatementatline7constructsaninstanceoftheinnerclass?
A.InsideOnewei=eo.newInsideOn();
B.Eo.InsideOneei=eo.newInsideOne();
C.InsideOneei=EnclosingOne.newInsideOne();
D.EnclosingOne.InsideOneei=eo.newInsideOne();
Answer:
D
QuestionNo15
Exhibit:
1.interfacefoo{
2.intk=0;
3.]
4.
5.publicclasstestimplementsFoo(
6.publicstaticvoidmain(Stringargs[])(
7.inti;
8.Testtest=newtest();
9.i=test.k;
10.i=Test.k;
11.i=Foo.k;
12.)
13.)
14.
Whatistheresult?
A.Compilationsucceeds.
B.Anerroratline2causescompilationtofail.
C.Anerroratline9causescompilationtofail.
D.Anerroratline10causescompilationtofail.
E.Anerroratline11causescompilationtofail.
Answer:
A
QuestionNo16
Given:
1.//pointX
2.publicclassfoo(
3.publicstaticvoidmain(String[]args)throwsException{
4.printWriterout=newPrintWriter(new
5.java.io.outputStreamWriter(System.out),true;
6.out.printIn(“Hello”);
7.}
8.)
WhichstatementatPointXonline1allowsthiscodetocompileandrun?
A.Importjava.io.PrintWriter;
B.Includejava.io.PrintWriter;
C.Importjava.io.OutputStreamWriter;
D.Includejava.io.OutputStreamWriter;
E.Nostatementisneeded.
Answer:
A
QuestionNo17
WhichtwostatementsarereservedwordsinJava?
(ChooseTwo)
A.Run
B.Import
C.Default
D.Implement
Answer:
B,C
QuestionNo18
Whichthreearevaliddeclarationsofafloat?
(ChooseThree)
A.Floatfoo=-1;
B.Floatfoo=1.0;
C.Floatfoo=42e1;
D.Floatfoo=2.02f;
E.Floatfoo=3.03d;
F.Floatfoo=0x0123;
Answer:
A,D,F
LeadingthewayinITtestingandcertificationtools,
QuestionNo19
Given:
8.intindex=1;
9.boolean[]test=newBoolean[3];
10.booleanfoo=test[index];
Whatistheresult?
A.Foohasthevalueof0.
B.Foohasthevalueofnull.
C.Foohasthevalueoftrue.
D.Foohasthevalueoffalse.
E.Anexceptionisthrown.
F.Thecodewillnotcompile.
Answer:
D
QuestionNo20
Given:
1.publicclasstest(
2.publicstaticvoidmain(string[]args){
3.stringfoo=args[1];
4.stringfoo=args[2];
5.stringfoo=args[3];
6.}
7.}
Andcommandlineinvocation:
JavaTestredgreenblue
Whatistheresult?
A.Bazhasthevalueof“”
B.Bazhasthevalueofnull
C.Bazhasthevalueof“red”
D.Bazhasthevalueof“blue”
E.Baxhasthevalueof“green”
F.Thecodedoesnotcompile.
G.Theprogramthrowsanexception.
Answer:
G
QuestionNo21
Given:
8.intindex=1;
9.int[]foo=newint[3];
10.intbar=foo[index];
11.intbaz=bar+index;
Whatistheresult?
A.Bazhasthevalueof0
B.Bazhasthevalueof1
C.Bazhasthevalueof2
D.Anexceptionisthrown.
E.Thecodewillnotcompile.
Answer:
B
QuestionNo22
Given:
1.publicclassfoo{
2.publicstaticvoidmain(String[]args){
3.Strings;
4.system.out.printIn(“s=”+s);
5.}
6.}
Whatistheresult?
A.Thecodecompilesand“s=”isprinted.