JAVA认证历年真题:SCJP考试真题和解析_第1页
JAVA认证历年真题:SCJP考试真题和解析_第2页
JAVA认证历年真题:SCJP考试真题和解析_第3页
JAVA认证历年真题:SCJP考试真题和解析_第4页
JAVA认证历年真题:SCJP考试真题和解析_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

JAVA认证历年真题:SCJP考试真题和解析(1)

JAVA认证历年真题:SCJP考试真题和解析例题1:

Choosethethreevalididentifiersfromthoselistedbelow.

A.IDoLikeTheLongNameCiass

B.$byte

C.const

D._ok

E.3_case

解答:A,B,D

点评:Java中的标示符必须是字母、美元符($)或下划线(_)开头。关键字与保留字不能作

为标示符。选项C中的const是Java的保留字,所以不能作标示符。选项E中的3_case以

数字开头,违反了Java的规则。例题2:

Howcanyouforcegarbagecollectionofanobject?

A.Garbagecollectioncannotbeforced

B.CallSystem.gc().

C.CallSystem.gc(),passinginareferencetotheobjecttobegarbagecollected.

D.CallRuntime.gc().

E.Setallreferencestotheobjecttonewvalues(null,forexample).

解答:A

点评:在Java中垃圾收集是不能被强迫立即执行的。调用System.gc()或Runtime.gc。静态

方法不能保证垃圾收集器的立即执行,因为,也许存在着更高优先级的线程。所以选项B、

D不正确。选项C的错误在于,System.gc。方法是不接受参数的。选项E中的方法可以使

对象在下次垃圾收集器运行时被收集。

例题3:

Considerthefollowingclass:

1.classTest(inti){

2.voidtest(inti){

3.System.out.println(4tIamanint.'');

4.)

5.voidtest(Strings){

6.System.out.printlnC'Iamastring.^^);

7.}8.9.publicstaticvoidmain(Stringargs){

10.Testt=newTest();

ll.charch"';

12.t.test(ch);

13.}

14.}

Whichofthestatementsbelowistrue?(Chooseone.)

A.Line5willnotcompile,becausevoidmethodscannotbeoverridden.

B.Line12willnotcompile,becausethereisnoversionoftest()thatrakesacharargument.

C.Thecodewillcompilebutwillthrowanexceptionatline12.

D.Thecodewillcompileandproducethefollowingoutput:Iamanint.

E.Thecodewillcompileandproducethefollowingoutput:IamaString.

解答:D

点评:在第12行,16位长的char型变量ch在编译时会自动转化为一个32位长的int型,

并在运行时传给voidtest(inti)方法。

QuestionNo:1

Given:

1.publicclasstest(

2.publicstaticvoidmain(Stringargs){

3.inti=OxFFFFFFFl;

4.intj=〜i;

5.

6.}

7.)

Whatisthedecimalvalueofjatline5?

A.O

B.1

C.14

D.-15

E.Anerroratline3causescompilationtofail.

F.Anerroratline4causescompilationtofail.

Answer:D

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<lOlmethodB(4);

ll.b=i<1011methodB(8);

12.)

13.

14.publicstaticvoidmain(Stringargs}(

15.methodA(0);

16.system.out.println(j);

17.)

18.)

Whatistheresult?

A.TheprogramprintsA”

B.Theprogramprihatistheoutput?

Answer:5

QuestionNo:5

Given:

1.publicclassFoo{

2.publicstaticvoidmain(Stringargs){

3.StringBuffera=newStringBuffer(<<A>>);

4.StringBufferb=newStringBuffer("B”);

5.operate(a,b);

6.system.out.println{a++b);

7.)

8.staticvoidoperate(StringBufferx,StringBuffery){

9.x.append{y};

10.y=x;

11.)

12.)

Whatistheresult?

A.Thecodecompilesandprints

B.Thecodecompilesandprints"A,A”.

C.Thecodecompilesandprints

D.Thecodecompilesandprints

E.Thecodecompilesandprints"AB,AB”.

F.ThecodedoesnotcompilebecausecannotbeoverloadedforStringBuffer.Answer:DIII

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=Value();

4.val+=3;

5.i=newInteger(val);

6.)

7.

8.publicstaticvoidmain(Stringargs[]){

9.Integeri=newInteger(0);

10.add3(i);

11.system.out.println(Value());

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=l.Of;

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,5relationship?(ChooseTwo)

A.publicinterfacePerson{}

publicclassEmployeeextendsPerson{}

B.publicinterfaceShape{}

publicclassEmployeeextendsShape{}

C.publicinterfaceColor{}

publicclassEmployeeextendsColor{}

D.publicclassSpecies{}

publicclassAnimal(privateSpeciesspecies;)

E.interfaceComponent{}

ClassContainerimplementsComponent(

PrivateComponent1]children;

)

Answer:D,E

QuestionNo:12

Whichstatementistrue?

A.Ananonymousinnerclassmaybedeclaredasfinal.

B.Ananonymousinnerclasscanbedeclaredasprivate.

C.Ananonymousinnerclasscanimplementmultipleinterfaces.

D.Ananonymousinnerclasscanaccessfinalvariablesinanyenclosingscope.

E.Constructionofaninstanceofastaticinnerclassrequiresaninstanceoftheenclosingouter

class.

Answer:DIII

QuestionNo13

Given:

1.packagefoo;

2.

3.publicclassOuter(

4.publicstaticclassInner(

5.)

6.)

Whichstatementistrue?

A.AninstanceoftheInnerclasscanbeconstructedwith“newOuter.Inner()”

B.Aninstanceoftheinnerclasscannotbeconstructedoutsideofpackagefoo.

C.Aninstanceoftheinnerclasscanonlybeconstructedfromwithintheouterclass.

D.Fromwithinthepackagebar,aninstanceoftheinnerclasscanbeconstructedwith”new

inner。"

Answer:A

QuestionNo14

Exhibit:

1.publicclassenclosingone(

2.publicclassinsideone{}

3.)

4.publicclassinertest(

5.publicstaticvoidmain(stringargs)(

6.enclosingoneeo=newenclosingone();

7.//insertcodehere

8.)

9.)

Whichstatemen

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论