《Java程序设计第五章继承、接口和抽象类程序阅读题及答案.docx》由会员分享,可在线阅读,更多相关《Java程序设计第五章继承、接口和抽象类程序阅读题及答案.docx(13页珍藏版)》请在第壹文秘上搜索。
1、Is现有publicclassParetpublicvoidchange(intx)publicclassChildextendsParent/覆盖父类change方法)下列哪个声明是正确的覆盖了父类的change方法?A.publicvoidchange(intx)B.protectedvoidchange(itx)C.publicvoidchange(Strings)D.publicvoidchange(itx,inty)正确答案:A2、classCaintnum=1;Ca(itm)this.nur=num;System.out.prit(this.num);classCbextendsC
2、aitnum=2;Cb(itnum)this.nur=num;System.out.prit(um);)publicstaticvoidmain(Strigargs)Caa=newCb(5);)运行代码,程序输出结果为:A.52B.51C.编译报错D.15正确答案:C3、下面关于继承的叙述正确的是()AJava类中只允许单一继承BJava中一个类不能同时继承一个类和实现一个接口CJava中一个类只能实现一个接口DJava中一个类可继承于多个类正确答案:A4、给定下列程序,请选出正确结果。classCatCat(itc)System.out.print(cat+c+);)classSubCate
3、xtendsCatSubCat(itc)super(5);System.out.print(cable);)SubCat()this(4);)publicstaticvoidmain(String口args)SubCatS=newSubCat();)A.cablecat5B.cableC.cat5D.cat5cable正确答案:D5、下列程序的输出是()。classOtherpublicOther()System.ot.prit(Other!);)publicclassDriverlextendsOtherpublicstaticvoidmai(Stringargs)newDriverl();
4、newOther();)A.0ther!0ther!B.Other!C.Other!Other!Other!D.编译出错正确答案:A6、请选出以下程序的输出结果classApublicvoidfcl()System.out.pritln(,Afundiscalling);)publicvoidfc2()fucl();)classBextendsApublicvoidfcl()System.out.pritln(,Bfundiscalling);)publicvoidfc3()System.out.pritln(,Bfuc3iscalling);)classCpublicstaticvoidma
5、in(Strigargs)Aa=newBQ;a.fucl();a.fuc2();a.fuc3();)A. AfundiscallingBfc3iscallingB. BfundiscallingBfc3iscallingC. AfundiscallingAfundiscallingBfc3iscallingD.编译错误正确答案:D7、请选出以下程序的输出结果publicclassChildextendsPeoplePeoplefather;publicChild(Stringname)System.out.prit(3);this.ame=name;father=newPeople(name+
6、:F);)publicChild()System.out.prit(4);)publicstaticvoidmain(Stringargs)newChild(Alice);)classPeopleStringname;publicPeopIeQSystem.out.prit(l);)publicPeople(Stringname)System.out.prit(2);this.ame=name;)A.123B.132C.32D.312正确答案:B8、请选出正确答案classParentStringone,two;publicParet(Striga,Stringb)one=a;two=b;pu
7、blicvoidprint()System.ot.printl(oe);)publicclassChildextendsParentpublicChild(Stringa,Stringb)super(a,b);)publicvoidprit()System.out.pritln(oe+,to+two);)publicstaticvoidmai(Stringarg)Parentp=newParet(south,north);Parentt=newChild(,east,west);p.print();t.prit();)A. southtonortheasttowestB. southeastt
8、owestC. Causeerrorduringcompilation.D. D.southtonortheast正确答案:B9、请选择正确的输出结果classGuypublicGuy()System.out.prit(,llll);)classCowboyextendsGuypublicCowboy()System.out.prit(2221);)classWranglerextendsCowboypublicWragler()System.out.prit(333l);)publicclassGreeting2publicstaticvoidmain(Stringargs)Guygl=ne
9、wGuy();Guyg2=newCowboy();Guyg3=newWrangler();)A.编译错误B.111,111,222,111,222,333,C.lll,111,222,222,333,D.llll222,333,正确答案:B10、给定以下程序classPencilpublicvoidwrite(Stringcontet)System.out.pritln(Write+cotet);)classRubberPenciIextendsPecilpublicvoidwrite(Stringcontet)System.out.pritln(,RubberWrite+cotet);publicvoiderase(Stringcotet)System.ot.printl(Erase+content);)执行下列代码的结果是哪项?Pencilp=ewPecil();(RubberPenciI)p).write(,Hello);A.RubberWriteHelloB.运行时抛出异常C.WriteHelloD.编译失败正确答案:B