java认证之SCJP考试试题及答案讲解_第1页
java认证之SCJP考试试题及答案讲解_第2页
java认证之SCJP考试试题及答案讲解_第3页
java认证之SCJP考试试题及答案讲解_第4页
java认证之SCJP考试试题及答案讲解_第5页
已阅读5页,还剩53页未读 继续免费阅读

下载本文档

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

文档简介

Question1

Given:

11.publicinterfaceStatus{

12./*insertcodehere*/intMY_VALUE=10;

13.}

Whichthreearevalidonline12?(Choosethree.)

A.final

B.static

C.native

D.public

E.private

F.abstract

Gprotected

ABD

Question2

Given:

10.publicclassBar{

11.staticvoidfoo(int...x){

12.//insertcodehere

13.1

14.)

Whichtwocodefragments,insertedindependentlyatline12,willallow

theclasstocompile?(Choosetwo.)

A.foreach(x)System.out.println(z);

B.fdr(intz:x)System.out.println(z);

C.while(x.hasNext())System.out.println(x.next());

D.for(inti=0;i<x.length;i++)System.out.println(x[i]);

BD

Question3

Given:

11.publicclassTest{

12.publicstaticvoidmain(String[]args){

13.intx=5;

14.booleanbl=true;

15.booleanb2=false;

16.

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

18.System.out.print(nl");

19.System.out.print(n2");

20.if((b2=true)&&bl)

21.System.out.print("3°);

22.)

23.}

Whatistheresult?

A.2

B.3

C.12

D.23

E.123

F.Compilationfails.

GAuexceptionalisthrownatruntime.

D

Question4

Given:

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

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

Whatistheresult?

A.Compilationfails.

B.Anexceptionisthrownatruntime.

C.Thevariablefirstissettonull.

D.Thevariablefirstissettoelements[0].

D

Question5

Given:

10.interfaceFoo{}

11.classAlphaimplementsFoo{}

12.classBetaextendsAlpha{}

13.classDeltaextendsBeta{

14.publicstaticvoidmain(Stringf]args){

15.Betax=newBeta();

16.//insertcodehere

17.}

18.}

Whichcode,insertedatline16,willcausea

java.lang.ClassCastException?

A.Alphaa=x;隐式向上造型

B.Foof=(Delta)x;beta不能转换为delta

C.Foof=(Alpha)x;

D.Betab=(Beta)(Alpha)x;

B

Question6

Given:

11.classCup{}

12.classPoisonCupextendsCup{}

21.publicvoidtakeCup(Cupc){

22.if(cinstanceofPoisonCup){

23.System.out.println("Inconceivable!");

24.}elseif(cinstanceofCup){

25.System.out.println("Dizzyingintellect!1');

26.}else{

27.System.exit(O);

28.}

29.}

Andtheexecutionofthestatements:

Cupcup=newPoisonCupO;

takeCup(cup);

Whatistheoutput?

A.Inconceivable!

B.Dizzyingintellect!

C.Thecoderunswithnooutput.

D.Anexceptionisthrownatruntime.

E.Compilationfailsbecauseofanerrorinline22.

A

Question7

Given:

11.publicstaticvoidtest(Stringstr){

12.if(str=nullIstr.length()==0){〃空指针异常琲短路str.length()==O也会执行所

以空指针异常

13.System.out.println(nStringisempty");

14.}else{

15.System.out.println(''Stringisnotempty");

16.}

17.}

Andtheinvocation:

31.test(null);

Whatistheresult?

A.Anexceptionisthrownatruntime.

B."Stringisempty"isprintedtooutput.

C.Compilationfailsbecauseofauerrorinline12.

D."Stringisnotempty"isprintedtooutput.

A

Question8

Given:

10.publicclassMyClass{

11.

12.publicIntegerstartingl;

13.publicvoidmethodA(){

14.Integeri=newInteger(25);

15.startingl=i;

16.methodB(i);

17.)

18.privatevoidmethodB(Integeri2){

19.i2=Value();

20.

21.)

22.}

IfmethodAisinvoked,whichtwoaretrueatline20?(Choosetwo.)

A.i2==startinglreturnstrue.

B.i2==startinglreturnsfalse.

C.i2.equals(startingl)returnstrue.

D.i2.equals(startingl)returnsfalse.

BC

Question9

WhichManclassproperlyrepresentstherelationship"Manhasabest

friendwhoisaDog"?

A.classManextendsDog{}

B.classManimplementsDog{}

C.classMan{privateBestFrienddog;}

D.classMan{privateDogbestFriend;}

E.classMan{privateDog<bestFriend>}

F.classMan{privateBestFriend<dog>}〃无变量

D

Question10

Given:

11.publicclassItemTest{

12.privatefinalintid;

13.publicItemTest(intid){this.id=id;}

14.publicvoidupdateld(intnewld){id=newld;)

15.

16.publicstaticvoidmain(String[]args){

17.ItemTestfa=newItemTest(42);

18.fa.updateld(69);

19.System.out.println(fa.id);

20.)

21.)

Whatistheresult?

A.Compilationfails.

B.Anexceptionisthrownatruntime.

C.TheattributeidintheItemobjectremainsunchanged.

D.TheattributeidintheItemobjectismodifiedtothenewvalue.

E.AnewItemobjectiscreatedwiththepreferredvalueintheid

attribute.

A

Question11

Given:

15.publicclassYippee{

16.publicstaticvoidmain(String[]args){

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

18.System.out.print(args[x]+””);

19.}

20.}

21.)

andtwoseparatecommandlineinvocations:

javaYippee

javaYippee1234

Whatistheresult?

A.Nooutputisproduced.

123

B.Nooutputisproduced.

234

C.Nooutputisproduced.

1234

D.Anexceptionisthrownatruntime.

123

E.Anexceptionisthrownatruntime.

234

F.Anexceptionisthrownatrijntime.

1234

B

Question12

12.Given:

13.publicclassPass{

14.publicstaticvoidmain(String[]args){

15.intx=5;

16.Passp=newPass();

17.p.doStuff(x);

18.System.out.print("mainx="+x);

19.)

20.

21.voiddoStuff(intx){

22.System.out.print("doStuffx=n+x++);

23.}

24.}

Whatistheresult?

A.Compilationfails.

B.Anexceptionisthrownatruntime.

C.doStuffx=6mainx=6

D.doStuffx=5mainx=5

E.doStuffx=5mainx=6

F.doStuffx=6mainx=5

D

Question13

Given:

10.packagecom.sun.scjp;

11.publicclassGeodetics{

12.publicstaticfinaldoubleDIAMETER=12756.32;//kilometers

13.}

WhichtwocorrectlyaccesstheDIAMETERmemberoftheGeodetics

class?(Choosetwo.)

A.importcom.sun.scjp.Geodetics;

publicclassTerraCarta{

publicdoublehalfwayO{returnGeodetics.DIAMETER/2.0;}}

B.importstaticcom.sun.scjp.Geodetics;

publicclassTerraCarta{

publicdoublehalfwayO{returnDIAMETER/2.0;}}

C.importstaticcom.sun.scjp.Geodetics.//static导入类中的所有静态成员

publicclassTerraCarta{

publicdoublehalfwayO{returnDIAMETER/2.0;}}

D.packagecom.sun.scjp;

publicclassTerraCarta{

publicdoublehalfwayO{returnDIAMETER/2.0;}}

AC

Question14

Given:

10.classNav{

11.publicenumDirection{NORTH,SOUTH,EAST,WEST}

12.)

13.publicclassSprite{

14.//insertcodehere

15.}

Whichcode,insertedatline14,allowstheSpriteclasstocompile?

A.Directiond=NORTH;

B.Nav.Directiond=NORTH;

C.Directiond=Direction.NORTH;

D.Nav.Directiond=Nav.Direction.NORTH;

D

Question15

Given:

10.interfaceFoo{intbar();}

11.publicclassSprite{

12.publicintfubar(Foofbo){returnfoo.bar();}

13.publicvoidtestFoo(){

14.fubar(

15.//insertcodehere

16.);

17.)

18.}

Whichcode,insertedatline15,allowstheclassSpritetocompile?

A.Foo{publicintbar(){return1;}}

B.newFoo{publicintbar(){return1;}}

C.newFoo(){publicintbar(){returnI;)}〃匿名类的使用

D.newclassFoo{publicintbar(){return1;})

C

Question16

Given:

11.publicclassCounter{

12.publicstaticvoidmain(String[]args){

13.intnumArgs=/*insertcodehere*/;

14.)

15.}

andthecommandline:

javaCounteronefred42

Whichcode,insertedatline13,capturesthenumberofarguments

passedintotheprogram?

A.args.count

B.args.length

C.args.count()

D.args.length()

E.args.getLength()

B

Question17

Given:

1.packagesun.sqp;

2.publicenumColor{RED,GREEN,BLUE}

1.packagesun.beta;

2.//insertcodehere

3.publicclassBeta)

4.Colorg=GREEN;

5.publicstaticvoidmain(String[]argv)

6.{System.out.println(GREEN);}

7.)

TheclassBetaandtheenumColorareindifferentpackages.

Whichtwocodefragments,insertedindividuallyatline2oftheBeta

declaration,willallowthiscodetocompile?(Choosetwo.)

A.importsun.scjp.Color.*;

B.importstaticsun.scjp.Color.*;

C.importsun.scjp.Color;importstaticsun.scjp.Color.*;

D.importsun.scjp.*;importstaticsun.scjp.Color.*;

E.importsun.scjp.Color;importstaticsun.scjp.Color.GREEN;

CDE

Question18

Given:

1.publicinterfaceA{

2.StringDEFAULT_GREETING="HelloWorld1';

3.publicvoidmethod1();

4.}

AprogrammerwantstocreateaninterfacecalledBthathasAasits

parent.Whichinterfacedeclarationiscorrect?

A.publicinterfaceBextendsA{}

B.publicinterfaceBimplementsA{}

C.publicinterfaceBinstanceOfA{}

D.publicinterfaceBinheritsFromA{}

A

Question19

Given:

1.classTestA{

2.publicvoidstart(){System.out.println(nTestAH);}

3.}

4.publicclassTestBextendsTestA{

5.publicvoidstart(){System.out.println("TestBH);}

6.publicstaticvoidmain(String[]args){

7.((TestA)newTestB()).start();//TestB对象

8.}

9.}

Whatistheresult?

A.TestA

B.TestB

C.Compilationfails.

D.Anexceptionisthrownatruntime.

B

Question20

Given:

1.interfaceTestA{StringtoStringO;}

2.publicclassTest{

3.publicstaticvoidmain(String[]args){

4.System.out.println(newTestA(){

5.publicStringtoString(){return“test";}

6.});

7.)

8.}

Whatistheresult?

A.test

B.null

C.Anexceptionisthrownatruntime.

D.Compilationfailsbecauseofanerrorinline1.

E.Compilationfailsbecauseofanerrorinline4.

F.Compilationfailsbecauseofanenorinline5.

A

Question21

Given:

11.publicabstractclassShape{

12.intx;

13.inty;

14.publicabstractvoiddraw();

15.publicvoidsetAnchor(intx,inty){

16.this.x=x;

17.this.y=y;

18.}

19.}

andaclassCirclethatextendsandfullyimplementstheShapeclass.Whichiscorrect?

A.Shapes=newShape();

s.setAnchor(10J0);

s.draw();

B.Circlec=newShape();

c.setAnchor(10,10);

c.draw();

C.Shapes=newCircle();

s.setAnchor(IOJO);

s.draw();

D.Shapes=newCircle();

s->setAnchor(10,10);

s->draw();

E.Circlec=newCircle();

c.Shape.setAnchor(10,10);

c.Shape.draw();

C

Question22

Given:

10.abstractpublicclassEmployee{

11.protectedabstractdoublegetSalesAmount();

12.publicdoublegetCommision(){

13.returngetSalesAmount()*0.15;

14.}

15.}

16.classSalesextendsEmployee{

17.//insertmethodhere

18.}

Whichtwomethods,insertedindependentlyatline17,correctly

completetheSalesclass?(Choosetwo.)

A.doublegetSalesAmount(){return1230.45;}

B.publicdoublegetSalesAmount(){return1230.45;}

C.privatedoublegetSalesAmount(){return1230.45;}

D.protecteddoublegetSalesAmount(){return1230.45;}

BD

Question23

Given:

10.interfaceData{publicvoidload();}

11.abstractclassInfo{publicabstractvoidload();}

WhichclasscorrectlyusestheDatainterfaceandInfoclass?

A.publicclassEmployeeextendsInfbimplementsData{

publicvoidload(){/*dosomething*/}

)

B.publicclassEmployeeimplementsInfoextendsData)

publicvoidload(){/*dosomething*/}

)

C.publicclassEmployeeextendsInfoimplementsData{

publicvoidload(){/*dosomething*/}

publicvoidlnfo.load(){/*dosomething*/}

)

D.publicclassEmployeeimplementsInfoextendsData{

publicvoidData.load(){/*dsomething*/}

publicvoidload(){/*dosomething*/}

)

E.publicclassEmployeeimplementsInfoextendsData{

publicvoidload(){/*dosomething*/}

publicvoidInfo.load(){/*dosomething*/}

)

F.publicclassEmployeeextendsInfbimplementsData{

publicvoidData.load(){/*dosomething*/}

publicvoidInfo.load(){/*dosomething*/}

)

A

Question24

Given:

11.publicabstractclassShape{

12.privateintx;

13.privateinty;

14.publicabstractvoiddraw();

15.publicvoidsetAnchor(intx,inty){

16.this.x=x;17.this.y=y;

18.)

19.)

WhichtwoclassesusetheShapeclasscorrectly?(Choosetwo.)

A.publicclassCircleimplementsShape{

privateintradius;

)

B.publicabstractclassCircleextendsShape{

privateintradius;

)

C.publicclassCircleextendsShape{

privateintradius;

publicvoiddraw();

)

D.publicabstractclassCircleimplementsShape{

privateintradius;

publicvoiddraw();

)

E.publicclassCircleextendsShape{

privateintradius;

publicvoiddraw(){/*codehere*/}

F.publicabstractclassCircleimplementsShape{

privateintradius;

publicvoiddraw(){/codehere*/}

)

BE

Question25

Whichtwoclassescorrectlyimplementboththejava.lang.Runnable

andthejava.lang.Clonableinterfaces?(Choosetwo.)

A.publicclassSession

implementsRunnable,Clonable{

publicvoidrun();

publicObjectclone();

)

B.publicclassSession

extendsRunnable,Clonable{

publicvoidrun(){/dosomething*/}

publicObjectclone(){/makeacopy*/}

)

C.publicclassSession

implementsRunnable,Clonable{

publicvoidrun(){/dosomething*/}

publicObjectclone(){/*makeacopy*/}

)

D.publicabstractclassSession

implementsRunnable,Clonable{

publicvoidrun(){/dosomething*/)

publicObjectclone(){/*makeacopy*/}

)

E.publicclassSession

implementsRunnable,implementsClonable{

publicvoidrun(){/dosomething*/)

publicObjectclone(){/makeacopy*/}

)

CD

Question26

1.publicclassGoTest{

2.publicstaticvoidmain(String[]args){

3.Sentea=newSente();a.go();

4.Gobanb=newGoban();b.go();

5.Stonec=newStone();c.go();

6}

7.}

8.

9.classSenteimplementsGo{

10.publicvoidgo(){System.out.println(ngoinSente.'1);}

H.)

12.

13.classGobanextendsSente{

14.publicvoidgo(){System.out.print]n(HgoinGoban");}

15.}

16.

17.classStoneextendsGobanimplementsGo{}

18.

19.interfaceGo{publicvoidgo();}

Whatistheresult?

A.goinGoban

goinSente

goinSente

B.goinSente

goinSente

goinGoban

C.goinSente

goinGoban

goinGoban

D.goinGoban

goinGoban

goinSente

E.Compilationfailsbecauseofanerrorinline17.

C

Question27

Given:

11.publicstaticvoidparse(Stringstr){

12.try{

13.floatf=Float.parseFloat(str);

14.}catch(NumberFormatExceptionnfe){

15.f=0;〃f在try里定义这里找不到f

16.}finally{

17.System.out.println(f);

18.}

19.)

20.publicstaticvoidmain(String[]args){

21.parse(uinvalid");

22.}

Whatistheresult?

A.0.0

B.Compilationfails.

C.AParseExceptionisthrownbytheparsemethodatruntime.

D.ANumberFormatExceptionisthrownbytheparsemethodat

runtime.

B

Question28

1.publicclassTest{

2.intx=12;

3.publicvoidmethod(intx){

4.x+=x;

5.System.out.println(x);

6.)

7J

Given:

34.Testt=newTest();

35.t.method(5);

Whatistheoutputfromline5oftheTestclass?

A.5

B.10

C.12

D.17

E.24

B

Question29

Given:

55.int[]x={1,2,34,5};

56.inty[]=x;

57.System.out.println(y[2J);

Whichistrue?

A.Line57willprintthevalue2.

B.Line57willprintthevalue3.

C.Compilationwillfailbecauseofanerrorinline55.

D.Compilationwillfailbecauseofanerrorinline56.

B

Question30

Given:

35.String#name="JaneDoe";

36.int$age=24;

37.Double_height=123.5;

38.double〜temp=37.5;

Whichtwoaretrue?(Choosetwo.)

A.Line35willnotcompile.

B.Line36willnotcompile.

C.Line37willnotcompile.

D.Line38willnotcompile.

AD

Question31

Whichtwocodefragmentscorrectlycreateandinitializeastaticarray

ofintelements?(Choosetwo.)

A.staticfinalint[]a={100,200};

B.staticfinalint[]a;

static{a=newint[2];a[0]=100;a[l]=200;}

C.staticfinalint[]a=newint[2]{100,200};〃后面已初始int[2]不能给大小

D.staticfinalint[]a;

staticvoidinit(){a=newint[3];a[0]=100;a[l]=200;}

AB

Question32

Given:

11.publicclassBall{

12.publicenumColor{RED,GREEN,BLUE};

13.publicvoidfoo(){

14.//insertcodehere

15.{System.out.println(c);}

16.}

17.}

Whichcodeinsertedatline14causesthefoomethodtoprintRED,

GREEN,andBLUE?

A.for(Colorc:Color,values。)〃枚举的方法

B.for(Colorc=RED;c<=BLUE;C++)

C.for(Colorc;c.hasNext();c.next())

D.for(Colorc=Color[0];c<=Color[2];C++)

E.for(Colorc=Color.RED;c<=Color.BLUE;C++)

A

Question33

Given:

10.publicclassFabric

11.publicenumColor{

12.RED(OxfroOOO),GREEN(OxOOfroO),BLUE(0x0000ff);

13.privatefinalintrgb;

14.Color(intrgb){this.rgb=rgb;}

15.publicintgetRGB(){returnrgb;}

16.);

17.publicstaticvoidmain(String[]argv){

18.//insertcodehere

19.}

20.}

Whichtwocodefragments,insertedindependentlyatline18,allowthe

Fabricclasstocompile?(Choosetwo.)

A.ColorskyColor=BLUE;

B.ColortreeColor=Color.GREEN;

C.Colorpurple=newColor(OxffOOff);

D.if(RED.getRGB()<BLUE.getRGB()){}

E.Colorpurple=Color.BLUE+Color.RED;

F.if(Color.RED.ordinal()<Color.BLUE.ordinal()){}〃ordinal()下标方法

BF

单例模式的两种方法:

classA

(

privatestaticAa=newA();

privateA()

{

)

publicstaticAgetInstance()

(

returna;

)

)

classA

{

privatestaticAa;

privateA()

}

publicstaticAgetInstance()

{

if(a==nul1)

(

a=newA();

)

returna;

)

)

Question34

Givenclassesdefinedintwodifferentfiles:

1.packageutil;

2.publicclassBitUtils{

3.publicstaticvoidprocess(byte[]){/*morecodehere*/}

4.)

1.packageapp;

2.publicclassSomeApp{

3.publicstaticvoidmain(String[]args){

4.byte[]bytes=newbyte[256J;

5.//insertcodehere

6.)

7.}

Whatisrequiredatline5inclassSomeApptousetheprocessmethod

ofBitUtils?

A.process(bytes);

B.BitUcess(bytes);

C.util.BitUcess(bytes);

D.SomeAppcannotusemethodsinBitUtils.

E.importutil.BitUtils.*;process(bytes);

C

Question35

Given:

11.publicstaticvoidmain(String[]args){

12.Objectobj=newint[]{1,2,3);

13.int[]someArray=(int[])obj;

14.for(inti:someArray)System.out.print(i+“”);

15.}

Whatistheresult?

A.123

B.Compilationfailsbecauseofanerrorinline12.

C.Compilationfailsbecauseofanerrorinline13.

D.Compilationfailsbecauseofanerrorinline14.

E.AClassCastExceptionisthrownatruntime.

A

Question36

Given:

10.classFoo{

11.staticvoidalpha(){/*morecodehere*/}

12.voidbeta(){/*morecodehere*/}

13.}

Whichtwoaretrue?(Choosetwo.)

A.Foo.beta()isavalidinvocationofbeta().

B.Foo.alpha()isavalidinvocationofalpha().

C.Methodbeta()candirectlycallmethodalpha().

D.Methodalpha()candirectlycallmethodbeta().

CB

Question37

Aprogrammerneedstocreatealoggingmethodthatcanacceptan

arbitrarynumberofarguments.Forexample,itmaybecalledinthese

ways:

loglt(nlogmessage1");

loglt(nlogmessage2","logmessages'1);

logIt(Mlogmessaged","logmessage5n,"logmessage6);

Whichdeclarationsatisfiesthisrequirement?

A.publicvoidlogIt(String*msgs)

B.publicvoidloglt(String[]msgs)

C.publicvoidloglt(String...msgs)

D.publicvoidlogIt(Stringmsgl,Stringmsg2,Stringmsg3)

C

Question38

Aprogrammerisdesigningaclasstoencapsulatetheinformation

aboutaninventoryitem.AJavaBeanscomponentisneededto

dothis.TheInventoryitemclasshasprivateinstancevariablestostore

theiteminformation:

10.privateintitemld;

11.privateStringname;

12.privateStringdescription;

WhichmethodsignaturefollowstheJavaBeansnamingstandardsfor

modifyingtheitemldinstancevariable?

A.itemID(intitemld)

B.update(intitemld)

C.setltemld(intitemld)

D.mutateltemld(intitemld)

E.updateItemID(intitemld)

C

Question39

1.publicclassA{

2.

3.privateintcounter=0;

4.

5.publicstaticintgetInstanceCount(){

6.returncounter;〃静态方法里不能使用非静态变量

7.}

8.

9.publicA(){

10.counter++;

H.)

12.

13.}

GiventhiscodefromClassB:

25.Aal=newA();

26.Aa2=newA();

27.Aa3=newA();

28.System.out.printIn(A.getInstanceCount());

Whatistheresult?

A.CompilationofclassAfails.

B.Line28printsthevalue3toSystem.out.

C.Line28printsthevalue1toSystem.out.

D.Aruntimeerroroccurswhenline25executes.

E.Compilationfailsbecauseofanerroronline28.

A

Question40

AJavaBeanscomponenthasthefollowingfield:

11.privatebooleanenabled;

WhichtwopairsofmethoddeclarationsfollowtheJavaBeansstandard

foraccessingthisfield?(Choosetwo.)

A.publicvoidsetEnabled(booleanenabled)

publicbooleangetEnabled()

B.publicvoidsetEnabled(booleanenabled)

publicvoidisEnabled()

C.publicvoidsetEnabled(booleanenabled)

publicbooleanisEnabled()

D.publicbooleansetEnabled(booleanenabled)

publicbooleangetEnabled()

AC

Question41

41.Given:

10.classOne{

11.publicOnefoo(){returnthis;)

12.)

13.classTwoextendsOne{

14.publicOnefoo(){returnthis;}

15.}

16.classThreeextendsTwo{

17.//insertmethodhere

18.}

Whichtwomethods,insertedindividually,correctlycompletetheThreeclass?(Choosetwo.)

A.publicvoidfoo(){}

B.publicintfoo(){return3;}

C.publicTwofoo(){returnthis;}

D.publicOnefoo(){returnthis;}

E.publicObjectfoo(){returnthis;}

CD

Question42

Given:

10.classOne{

11.voidfoo(){}

12.)

13.classTwoextendsOne{

14.//insertmethodhere

15.}

Whichthreemethods,insertedindividuallyatline14,willcorrectly

completeclassTwo?(Choosethree.)

A.intfoo(){/*morecodehere*/}

B.voidfoo(){/*morecodehere*/}

C.publicvoidfoo(){/*morecodehere*/}

D.privatevoidfoo(){/*morecodehere*/}

E.protectedvoidfoo(){/*morecodehere*/)

BCE

Question43

1.publicinterfaceA{

2.publicvoiddoSomething(Stringthing);

3.}

1.publicclassAlmplimplementsA{

2.publicvoiddoSomething(Stringmsg){}

3.}

1.publicclassB{

2.publicAdoit(){

3.//morecodehere

4.}

5.

6.publicStringexecute(){

7.//morecodehere

8.}

9.}

1.publicclassCextendsB{

2.publicAlmpldoit(){

3.//morecodehere

4.}

5.

6.publicObjectexecute(){〃不能重写

7.//morecodehere

8.}

9.}

Whichstatementistrueabouttheclassesandinterfacesinthe

exhibit?

A.Compilationwillsucceedforallclassesandinterfaces.

B.CompilationofclassCwillfailbecauseofanerrorinline2.

C.CompilationofclassCwillfailbecauseofanerrorinline6.

D.CompilationofclassAlmplwillfailbecauseofanerrorinline2.

C

Question44

1.publicclassA{

2.publicStringdoit(intx,inty){

3.return"a";

4.)

5.

6.publicStringdoit(int...vals){

7.return"b";

8.)

9.)

Given:

25.Aa=newA();

26.System.out.println(a.doit(4,5));

Whatistheresult?

A.Line26prints"a"toSystem.out.

B.Line26prints"b"toSystem.out.

C.Anexceptionisthrownatline26atruntime.

D.CompilationofclassAwillfailduetoanerrorinline6.

A

Question45

Given:

1.publicclassA{

2.publicvoiddoit(){

3.}

4.publicStringdoit(){〃不构成重载不能同时存在,参数列表相同

5.return"a";

6.)

7.publicdoubledoit(intx){

8.return1.0;

9.}

10.}

Whatistheresult?

A.Anexceptionisthrownatruntime.

B.Compilationfailsbecauseofanerrorinline7.

C.Compilationfailsbecauseofanerrorinline4.

D.CompilationsucceedsandnoruntimeerrorswithclassAoccur.

C

Question46

46.Given:

10.classLine{

11.publicstaticclassPoint{}

12.}

13.

14.classTriangle{

15.//insertcodehere

16.}

Whichcode,insertedatline15,createsaninstanceofthePointclass

definedinLine?

A.Pointp=newPoint();

B.Line.Pointp=newLine.Point();

C.ThePointclasscannotbeinstatiatedatline15.

D.Line1=newLine();1.Pointp=newl.Point();

B

Question47

Given:

10.classLine{

11.publicclassPoint{publicintx,y;}

12.publicPointgetPoint(){returnnewPoint();}

13.}

14.classTriangle{

15.publicTriangle(){

16.//insertcodehere

17.)

18.}

Whichcode,insertedatline16,correctlyretrievesalocalinstanceofa

Pointobject?

A.Pointp=Line.getPoint();

B.Line.Pointp=Line.getPoint();

C.Pointp=(newLine()).getPoint();

D.Line.Pointp=(newLine()).getPoint();

D

Question48

Given:

10.classOne{

11.publicOne(){System.out.print(l);}

12.)

13.classTwoextendsOne{

14.publicTwo(){System.out.print(2);}

15.)

16.classThreeextendsTwo{

17.publicThree(){System.out.print(3);}

18.}

19.publicclassNumbers{

20.publicstaticvoidmain(String[]argv){newThree();}

21.)

Whatistheresultwhenthiscodeisexecuted?

A.1

B.3

C.123

D.321

E.Thecoderimswithnooutput.

C

Question49

11.classPerson{

12.Stringname="Noname";

13.publicPerson(Stringnm){name=nm;}〃不是无参构造方法

14.}

15.

16.classEmployeeextendsPerson{

17.StringemplD="0000H;

18.publicEmployee(Stringid){emplD=id;}〃要用super

19.)

20.

21.publicclassEmployeeTest)

22.publicstaticvoidmain(String[]args){

23.Employeee=newEmployee(“4321");

24.System.out.println(e.empID);

25.}

26.}

Whatistheresult?

A.4321

B.0000

C.Anexceptionisthrownatruntime.

D.Compilationfailsbecauseofanerrorinline18.

D

Question50

Given:

1.publicclassPlant{

2.privateStringname;

3.publicPlant(Stringname){=name;}

4.publicStringgetName(){retumname;}

5.)

1.publicclassTreeextendsPlant{

2.publicvoidgrowFruit(){}

3.publicvoiddropLeaves(){}

4.}

Whichistrue?

A.Thecodewillcompilewithoutchanges.

B.ThecodewillcompileifpublicTree(){Plant();}isaddedtothe

Treeclass.

C.ThecodewillcompileifpublicPlant(){Tree();}isaddedtothe

Plantclass.

D.ThecodewillcompileifpublicPlant(){this(Hfern");}isaddedto

thePlantclass.

E.ThecodewillcompileifpublicPlant(){Plant(',femn);}isaddedto

thePlantclass.

D

Question51

11.publicclassBootchy{

12.intbootch;

13.Stringsnootch;

14.

15.publicBootchyO{

16.thisC^nootchy");

17.System.out.print("firstu);

18.)

19.

20.publicBootchy(Stringsnootch){

21.this(420,"snootchy1');

22.System.out.print(nsecond");

23.}

24.

25.publicBootchy(intbootch,Stringsnootch){

26.this.bootch=bootch;

27.this.snootch=snootch;

28.System.out.print("third”);

29.}

30.

31.publicstaticvoidmain(String[]args){

32.Bootchyb=newBootchyO;

33.System.out.print(b.snootch+"H+b.bootch);

34.}

35.}

Whatistheresult?

A.snootchy420thirdsecondfirst

B.snootchy420firstsecondthird

C.firstsecondthirdsnootchy420

D.thirdsecondfirstsnootchy420

E.thirdfirstsecondsnootchy420

F.firstsecondfirstthirdsnootchy420

D

Question52

温馨提示

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

评论

0/150

提交评论