重载和覆盖Word格式文档下载.docx

上传人:b****6 文档编号:21749388 上传时间:2023-02-01 格式:DOCX 页数:14 大小:17.61KB
下载 相关 举报
重载和覆盖Word格式文档下载.docx_第1页
第1页 / 共14页
重载和覆盖Word格式文档下载.docx_第2页
第2页 / 共14页
重载和覆盖Word格式文档下载.docx_第3页
第3页 / 共14页
重载和覆盖Word格式文档下载.docx_第4页
第4页 / 共14页
重载和覆盖Word格式文档下载.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

重载和覆盖Word格式文档下载.docx

《重载和覆盖Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《重载和覆盖Word格式文档下载.docx(14页珍藏版)》请在冰豆网上搜索。

重载和覆盖Word格式文档下载.docx

1.publicclassRectangle{

2.}

3.

4.publicclassSquareextendsRectangle{

5.}

WhatistherelationshipbetweenRectangleandSquare?

b/*¾

Ø

Î

Ç

Ò

»

ö

Õ

ý

·

A.hasa

B.isa

C.It'

sbothanisaandhasarelationship.

D.Therelationshipisneitheranisaorahasarelationship.

4.Given:

1.publicclassVehicle{

2.privateEnginetheEngine;

3.}

4.

5.publicclassEngine{

6.}

WhatistherelationshipbetweenVehicleandEngine?

a/*¿

¨

³

¢

¯

ú

B.isa

5.Given:

1.publicinterfaceMoveable{

2.publicvoidmoveObject();

5.publicclassBitmapimplementsMoveable{

6.publicvoidmoveObject(){

7.//bodyomitted

8.}

9.}

WhatistherelationshipbetweenMovableandBitmap?

b

A.hasa

D.Therelationshipisneitheranisanorahasarelationship.

6.Given:

1.classSuperTest{

2.publicdoublegetNumber(){

3.returnMath.random()*100;

4.}

6.

7.classTestextendsSuperTest{

8.publicintgetNumber(){

9.return(int)(Math.random()*100);

10.}

11.publicstaticvoidmain(String[]args){

12.Testt=newTest();

13.System.out.println(t.getNumber());

14.}

15.}

Whichoftheseresultscouldoccurfromthiscode?

(Chooseallthatapply)f/*×

À

à

Í

¡

A.59

B.34.234

C.134.234

D.134

E.100

F.Thiscodewillnotcompile.

7.Given:

8.publicintgetNumber(intmax){

9.return(int)(Math.random()*max);

11.

12.publicIntegergetNumber(intmax){

13.inttemp=(int)(Math.random()*max);

14.returnnewInteger(temp);

15.}

16.

17.publicstaticvoidmain(String[]args){

18.Testt=newTest();

19.System.out.println(t.getNumber());

20.}

21.}

Whichofthesestatementsistrue?

A.Thecodewillnotcompilecorrectlybecauseline19istryingtocallamethodthatdoesnotexistfortheclassTest.

B.Thecodedoesnotcompilebecauseofline12

C.Thecodedoesnotcompilebecauseofline14

D.Thereisnoambiguityastothereutrntypeinline12;

therefore,thiscodewillcompileandoutputadoublevalue

greaterthanorequalto0andlessthan100.

E.ThiscodewillnotcompilebecausethegetNumber()methodsintheTestclassmustallhavereturntypesofdouble.

8.Given:

1.publicclassA{

2.publicstaticvoidmain(String[]args){

3.newA().printResult(1,"

abc"

4);

5.privatevoidprintResult(inta,longb,intc){

6.System.out.println(a+b+c);

7.}

8.privatevoidprintResult(longa,Stringb,intc){

9.System.out.println(a+b+c);

11.}

A.ThecodewillnotcompilecorrectlybecausealongandaStringmaynotbeaddedtogetherinline9.

B.Thecodewillcompileandrunandwilldisplay1abc4inthestandardoutput.

B.Thecodewillcompileandrunandwilldisplay11234inthestandardoutput.

D.ThecodewillcompileandwillthrowaNumberFormatException.

9.Whenasubclassmethodhasthesamename,parameterlist,andreturntypeasamethodintheparentclass,thismethodissaidtobewhat?

d

A.Extended

B.Overloaded

C.Overextended

D.Overridden/*¸

²

10.Whichofthefollowingmustmatchexactlyforoverloadedmethodstocompilecorreclty?

(Choosethatallapply)d

A.Theparameterlist

B.Thereturntype

C.Theexceptionthrown

D.Noneoftheabove

11.Given:

1.publicclassTest{

2.publicstaticvoidmain(String[]args){

3.newTest().foo(1,2);

5.privatevoidfoo(inta,intb){

6.System.out.println("

int"

);

8.privatevoidfoo(longa,intb){

9.System.out.println("

long"

Whatwillhappenwhenyoucompileandrunthisprogram?

a

A.Thecodewillcompileandrun,anddisplayint.

B.Thecodewillcompileandrun,anddisplaylong.

C.Thecodewillnotcompile.

D.Thecodewillcompile,butthrowaruntimeexceptionwhenexecuted.

12.Given:

1.publicclassParent{

2.publicvoidexecute()throwsException{

3.//bodyomitted

4.}

6.publicclassChildextendsParent{

7.privatevoidexecute()throwsClassCastException{

8.//bodyomitted

9.}

10.}

Whatwillhappenwhenyoucompilethisprogram?

A.Theprogramwillcompilesuccessfully.

B.Theprogramwillnotcompilebecausetheexecute()inthesubclassthrowsadifferentexceptionthanintheparentclass.

C.Theprogramwillnotcompilebecausetheexecute()inthesubclasshaslessaccessibilitythanintheparentclass.

D.Theprogramwillnotcompilebecausetheexecute()inthesubclasshaslessaccessibliityandthrowsadifferentexceptionthanin

theparentclass.

13.Given:

2.publicvoidbaz(){

3.System.out.println("

A"

6.publicclassBextendsA{

7.publicstaticvoidmain(String[]args){

8.Aa=newB();

9.a.baz();

11.publicvodbaz(){

12.System.out.println("

B"

13.}

14.}

A.Theprogramcompiles,runs,anddisplayAinthestandardoutput.

B.Theprogramcompiles,runs,anddisplayBinthestandardoutput.

C.Theprogramcompiles,butthrowsaruntimeexception.

D.Theprogramdoesnotcompile.

14.Given:

3.newA().baz(1,2);

5.privatevoidbaz(inta,intb){

baz"

8.privatevoidfoo(inta,intb){

first"

11.privatebooleanfoo(inta,intb){

second"

13.returntrue;

Whichofthefollowingstatementsistrue?

A.Theprogramcompiles,runs,anddisplaysfirstinthestandardoutput.

B.Theprogramcompiles,runs,anddisplayssecondinthestandardoutput.

C.Theprogramcompiles,runs,anddisplaysbazinthestandardoutput.

15.Given:

2.protectedvoidstart()throwsClassCastException{

3.//bodyomitted

7.publicclassChildextendsTest{

8.publicvoidstart()throwsException{

9.//bodyomitted

B.Theprogramwillnotcompilebecausethestart()inthesubclassthrowsadifferentexceptionthanintheparentclass.

C.Theprogramwillnotcompilebecausethestart()inthesubclassispublic,whereasitisprotectedintheparentclass.

D.Theprogramwillnotcompilebecausethestart()inthesubclasshasdifferentaccessibilityandthrowsadifferentexceptionthanintheparentclass.

16.Whentwoormoremethodsinthesameclasshavethesamename,theyaresaidtobewhat?

A.Animplementationdetail

B.Overridden

C.Aninterface

D.Overloaded

17.Given:

1.publicclassExample{

3.newExample().locate(1.0,2);

5.privatevoidlocate(doublea,longb){

double-long"

8.privatevoidlocate(longa,intb){

long-int"

A.Thecodewillcompile,runanddisplaydouble-long.

B.Thecodewillcompile,runanddisplaylong-int.

18.Given:

2.publicSuperTest(){

Super!

"

8.publicstaticvoidmain(String[]args){

9.newTest();

11.publicTest(){

12.super();

13.this("

Great!

15.

16.publicTest(Stringname){

17.System.out.println(name);

18.}

19.}

Whatistheresultofthiscode?

f/*thisº

superÒ

ª

Å

Ô

£

¬

Ù

Æ

ð

A.Great!

B.Super!

C.Super!

D.Great!

E.Super!

19.Given:

3.newTest(4);

5.publicTest(){

okay"

8.publicTest(inti){

9.

11.}

Whichofthefollowinglinesofcodeshouldbeinsertedatline11sothattheoutputoftheprogramisokay?

c

A.super();

B.this;

C.Test();

D.this();

E.super();

20.Given:

1.publicclass

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > IT计算机 > 互联网

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1