第七章继承多态练习题

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

第七章继承多态一、选择题:1、分析:classA{A(){}}classBextendsA{//系统自动生成的构造方法和类的访问权限一样}哪两种说法是正确的?()A:类B的构造方法是public的.B:类B的构造方法包含对this()的调用.C:类B的构造方法没有参数.D:类B的构造方法包含对super()的调用.2、运行结果是:()classBase{Base(){System.out.print(Base);}}publicclassAlphaextendsBase{publicstaticvoidmain(String[]args){newAlpha();newBase();}}A:BaseB:BaseBaseC:编译失败.D:没有输出.E:运行时异常.3.程序的运行结果是?()A:编译失败.B:hellofromaC:hellofrombD:hellofrombE:hellofromahellofromahellofromb4.运行结果是:()classTestSuper{TestSuper(inti){}}classTestSubextendsTestSuper{}classTestAll{publicstaticvoidmain(String[]args){newTestSub();}}A:编译失败.B:程序运行没有异常.C:第7行抛出异常.D:第2行抛出异常.5.程序的运行结果是?()A:0B:1C:2D:编译失败.6.对于语句BisaD和BhasaC,一下哪两种说法是正确的?()A:D是B.B:B是D.C:D是C.D:B是C.E:D继承B.F:B继承D.7.运行结果是?()A:1B:2C:第8行编译失败.D:第14行编译失败.8.分析:publicclassConstOver{publicConstOver(intx,inty,intz){}}哪两个是对ConstOver的构造方法的重载?()A:ConstOver(){}B:protectedintConstOver(){}C:privateConstOver(intz,inty,bytex){}D:publicObjectConstOver(intx,inty,intz){}E:publicvoidConstOver(bytex,bytey,bytez){}9.运行结果是?()A:4,4B:4,5C:5,4D:5,5E:编译失败.10.分析:publicclassX{publicXaMethod(){returnthis;}}1)publicclassYextendsX{2)3)}在第2行可以插入哪两项?()A:publicvoidaMethod(){}B:privatevoidaMethod(){}C:publicvoidaMethod(Strings){}D:privateYaMethod(){returnnull;}E:publicXaMethod(){returnnewY();}11.运行结果是?()A:4,4B:4,5C:5,4D:5,5E:编译失败.12.以下哪两个重载了方法setVar()?()publicclassMethodOver{publicvoidsetVar(inta,intb,floatc){}}A:privatevoidsetVar(inta,floatc,intb){}B:publicintsetVar(inta,floatc,intb){returna;}C:protectedvoidsetVar(inta,intb,floatc){}D:publicintsetVar(inta,intb,floatc){returna;}E:protectedfloatsetVar(inta,intb,floatc){returnc;}13.分析:1)classBaseClass{2)privatefloatx=1.0f;3)protectedvoidsetVar(floatf){x=f;}4)}5)classSubClassextendsBaseClass{6)privatefloatx=2.0f;7)//insertcodehere8)}在第7行插入哪两个覆盖了方法setVar()?()A:voidsetVar(floatf){x=f;}B:publicvoidsetVar(intf){x=f;}C:publicvoidsetVar(floatf){x=f;}D:publicdoublesetVar(floatf){returnf;}E:publicfinalvoidsetVar(floatf){x=f;}F:protectedfloatsetVar(){x=3.0f;return3.0f;}14.运行结果是?()A:1B:2C:运行时异常.D:第8行编译错误.E:第14行编译错误.15.分析:classA{protectedintmethod1(inta,intb){return0;}}在A的子类中,以下哪两个方法是合法的?()A:publicintmethod1(inta,intb){return0;}B:privateintmethod1(inta,longb){return0;}C:privateintmethod1(inta,intb){return0;}D:publicshortmethod1(inta,intb){return0;}E:staticprotectedintmethod1(inta,intb){return0;}16.分析:1)publicabstractclassTest{2)publicabstractvoidmethodA();3)4)publicabstractvoidmethodB()5){6)System.out.println(Hello);7)}8)}哪两种改法,可以使程序通过编译?()A:给方法methodA()加方法体C:在Test的声明中去掉abstractB:用;替换第5-7行D:在方法methodA()的声明中去掉abstractE:在方法methodB()的声明中去掉abstract17.运行结果是:()1)abstractclassAbstractIt{2)abstractfloatgetFloat();3)}4)publicclassAbstractTestextendsAbstractIt{5)privatefloatf1=1.0f;6)privatefloatgetFloat(){returnf1;}7)}A:编译成功.B:运行时异常.C:第2行编译失败.D:第6行编译失败.18.在接口中哪两个方法的声明是合法的?()A:voidmethod1();B:publicvoidmethod2();C:staticpublicvoidmethod5();D:protectedvoidmethod3();E:finalpublicvoidmethod4();19.分析:1)publicinterfaceFoo{2)intk=4;3)}哪三项与第2行等价?()A:finalintk=4;B:publicintk=4;C:staticintk=4;D:abstractintk=4;E:volatileintk=4;F:protectedintk=4;20.分析:interfaceInter{}classAimplementsInter{}classBextendsA{B(){A[]arr=newA[10];booleanb1=thisinstanceofInter;booleanb2=arrinstanceofObject;System.out.println(b1=+b1+,b2=+b2);}}创建B的对象时会输出?()A:编译失败.B:b1=true,b2=trueC:b1=true,b2=falseD:b1=false,b2=trueE:b1=false,b2=false21.哪一个能通过编译?()A:newAnimal().soundOff();B:Lionl=Alpha1.get(meateater);C:Elephante=newAlpha1();D:newAlpha1().get(veggie).soundOff();22.分析:classPassenger{}classEngine{}interfaceTransportVehicle{voidloadPassengers();}interfaceHelicopterextendsTransportVehicle{intflyIt(Stringdirection);}abstractclassJetStreamimplementsHelicopter{}哪种说法是正确的?()A:TransportVehiclehasaPassenger.B:类Engine在类JetStream中.C:接口TransportVehicle可以形成多态的基础.D:继承JetStream的非抽象类可以随意声明方法loadPassengers().23.哪三个是isa关系?()A:publicclassX{}B:publicinterfaceShape{}publicclassYextendsX{}publicinterfaceRectangleextendsShape{}C:publicinterfaceColor{}D:publicclassSpecies{}publicclassShape{privateColorcolor;}publicclassAnimal{privateSpeciesspecies;}E:publicclassPerson{}F:interfaceComponent{}publicclassEmployee{classContainerimplementsComponent{publicEmployee(Personperson){}privateComponent[]children;}}24.运行结果是:()publicinterfaceTest{intfrood=42;}classTestImplimplementsTest{privatestaticintfrood;publicstaticvoidmain(String[]args){System.out.println(++frood);}}A:0B:1C:42D:43E:编译失败.F:运行时异常.25.运行结果是?()A:5B:10C:编译失败.D:运行时异常.26.运行结果是:()1)publicclassTest{2)publicstaticvoidmain(Stringargs[]){3)classFoo{4)publicinti=3;5)}6)Objecto=(Object)newFoo();7)Foofoo=(Foo)o;8)System.out.println(i=+foo.i);9)}10)}A:i=3C:第6行抛出ClassCastException异常.B:编译失败.D:第7行抛出ClassCastException异常.27.分析:Strings=abcde;Objectob=(Object)s;if(ob.equals(s)){System.out.println(AAAA);}else{System.out.println(BBBB);}if(s.equals(ob)){System.out.println(CCCC);}else{System.out.println(DDDD);}输出哪两行?()A:AAAAB:BBBBC:CCCCD:DDDD二、简答题1.简述类与类之间的关系2.简述继承的基本概念及继承的过程3.简述方法重写以及方法重载与方法重写的区别4.简述super关键字的用法5.简述重写equals方法的步骤6.简述instanceof关键字的用法7.简述接口和抽象类的区别8.简述什么是多态三、编程

1 / 10
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功