最新第七章继承多态练习题Word文档格式.docx
《最新第七章继承多态练习题Word文档格式.docx》由会员分享,可在线阅读,更多相关《最新第七章继承多态练习题Word文档格式.docx(12页珍藏版)》请在冰豆网上搜索。
![最新第七章继承多态练习题Word文档格式.docx](https://file1.bdocx.com/fileroot1/2022-10/19/33fb5eb9-f557-4bb4-9d6e-33ed38cde6fd/33fb5eb9-f557-4bb4-9d6e-33ed38cde6fd1.gif)
publicclassAlphaextendsBase{
publicstaticvoidmain(String[]args){
newAlpha();
newBase();
BaseB:
BaseBaseC:
编译失败.D:
没有输出.E:
运行时异常.
3.程序的运行结果是?
()
编译失败.B:
hellofromaC:
hellofromb
D:
hellofrombE:
hellofroma
hellofromahellofromb
4.运行结果是:
classTestSuper{
TestSuper(inti){}
classTestSubextendsTestSuper{}
classTestAll{
publicstaticvoidmain(String[]args){
newTestSub();
}
编译失败.B:
程序运行没有异常.
第7行抛出异常.D:
第2行抛出异常.
5.程序的运行结果是?
0B:
1C:
2D:
编译失败.
6.对于语句"
BisaD"
和"
BhasaC"
,一下哪两种说法是正确的?
()
D是B.B:
B是D.C:
D是C.D:
B是C.E:
D继承B.F:
B继承D.
7.运行结果是?
1B:
2C:
第8行编译失败.D:
第14行编译失败.
8.分析:
publicclassConstOver{
publicConstOver(intx,inty,intz){
}
哪两个是对ConstOver的构造方法的重载?
()
ConstOver(){}B:
protectedintConstOver(){}
privateConstOver(intz,inty,bytex){}
publicObjectConstOver(intx,inty,intz){}
E:
publicvoidConstOver(bytex,bytey,bytez){}
9.运行结果是?
4,4B:
4,5C:
5,4D:
5,5E:
10.分析:
publicclassX{
publicXaMethod(){returnthis;
1)publicclassYextendsX{
2)
3)}
在第2行可以插入哪两项?
publicvoidaMethod(){}B:
privatevoidaMethod(){}
publicvoidaMethod(Strings){}D:
privateYaMethod(){returnnull;
publicXaMethod(){returnnewY();
11.运行结果是?
12.以下哪两个重载了方法setVar()?
()
publicclassMethodOver{
publicvoidsetVar(inta,intb,floatc){
privatevoidsetVar(inta,floatc,intb){}B:
publicintsetVar(inta,floatc,intb){returna;
}
protectedvoidsetVar(inta,intb,floatc){}D:
publicintsetVar(inta,intb,floatc){returna;
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)//insertcodehere
8)}
在第7行插入哪两个覆盖了方法setVar()?
voidsetVar(floatf){x=f;
}B:
publicvoidsetVar(intf){x=f;
publicvoidsetVar(floatf){x=f;
}D:
publicdoublesetVar(floatf){returnf;
publicfinalvoidsetVar(floatf){x=f;
}F:
protectedfloatsetVar(){x=3.0f;
return3.0f;
14.运行结果是?
2C:
运行时异常.D:
第8行编译错误.E:
第14行编译错误.
15.分析:
protectedintmethod1(inta,intb){return0;
在A的子类中,以下哪两个方法是合法的?
publicintmethod1(inta,intb){return0;
}B:
privateintmethod1(inta,longb){return0;
privateintmethod1(inta,intb){return0;
}D:
publicshortmethod1(inta,intb){return0;
staticprotectedintmethod1(inta,intb){return0;
16.分析:
1)publicabstractclassTest{
2)publicabstractvoidmethodA();
3)
4)publicabstractvoidmethodB()
5){
6)System.out.println("
Hello"
7)}
8)}
哪两种改法,可以使程序通过编译?
给方法methodA()加方法体C:
在Test的声明中去掉abstract
B:
用"
;
"
替换第5-7行D:
在方法methodA()的声明中去掉abstract
在方法methodB()的声明中去掉abstract
17.运行结果是:
1)abstractclassAbstractIt{
2)abstractfloatgetFloat();
4)publicclassAbstractTestextendsAbstractIt{
5)privatefloatf1=1.0f;
6)privatefloatgetFloat(){returnf1;
编译成功.B:
运行时异常.C:
第2行编译失败.D:
第6行编译失败.
18.在接口中哪两个方法的声明是合法的?
voidmethod1();
B:
publicvoidmethod2();
C:
staticpublicvoidmethod5();
protectedvoidmethod3();
E:
finalpublicvoidmethod4();
19.分析:
1)publicinterfaceFoo{
2)intk=4;
哪三项与第2行等价?
finalintk=4;
publicintk=4;
staticintk=4;
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的对象时会输出?
b1=true,b2=trueC:
b1=true,b2=false
b1=false,b2=trueE:
b1=false,b2=false
21.哪一个能通过编译?
newAnimal().soundOff();
B:
Lionl=Alpha1.get("
meateater"
Elephante=newAlpha1();
D:
newAlpha1().get("
veggie"
).soundOff();
22.分析:
classPassenger{}
classEngine{}
interfaceTransportVehicle{
voidloadPassengers();
interfaceHelicopterextendsTransportVehicle{
intflyIt(Stringdirection);
abstractclassJetStreamimplementsHelicopter{}
哪种说法是正确的?
TransportVehicleha