ImageVerifierCode 换一换
格式:DOCX , 页数:21 ,大小:20.13KB ,
资源ID:9523411      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/9523411.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(基础第章继承与多态练习题.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

基础第章继承与多态练习题.docx

1、基础第章继承与多态练习题第4章 继承与多态一 选择题1. 编译和运行以下两文件结果是( D )。/文件P1.javapackage MyPackage;class P1 void afancymethod() System.out.println(What a fancy method); /文件 P2.javapackage YourPackage;import MyPackage.*;public class P2 extends P1 public static void main(String argv) P2 p2 = new P2(); p2.afancymethod(); A两个

2、均通过编译,P2运行时输出 What a fancy methodB没一个通过编译C两个均通过编译,但P2运行时出错DP1 通过编译,但P2出现编译错误2下列程序运行的结果是( A )。package a;package b;public class Dpublic static void main(String args) System.out.println(_,今天心情不错!);A出现编译错误B_,今天心情不错!C通过编译,运行时出错D以上都不对3Java的核心类库中哪个包,Java系统能自动引入( B )。Ajava.io Bjava.langC Djava.util4下列程序运行结果

3、是( A )。 private class Base Base() int i = 100; System.out.println(i); public class Pri extends Base static int i = 200; public static void main(String argv) Pri p = new Pri(); System.out.println(i); A编译错误 B200 C100 200 D1005下列程序运行结果是( C )。 class Base Base() int i = 100; System.out.println(i); public

4、 class Pri extends Base static int i = 200; public static void main(String argv) Pri p = new Pri(); System.out.println(i); A编译错误 B200 C100 200 D1006如何定义一个不能有子类的类Key( B )。Aclass Key Bfinal class Key Cpublic class Key Dclass Key final int i; 7哪个选项可以做为以下方法的覆盖方法( A )。public void add(int a) Apublic void

5、add(int b) Bvoid add(int a) Cpublic int add(int a) Dpublic void add(float a) 8在子类构造方法的哪个地方可以调用超类的构造方法( B )。 A任何地方B构造方法的第一条语句 C构造方法的最后一条语句 D不能在子类构造方法中调用超类的构造方法9下列程序的运行结果是( C )。 public class Test public static void test() this.print(); public static void print() System.out.println(Test); public static

6、 void main(String args ) test(); A输出TestB无输出结果C类编译错误,指示不能在static上下文中使用thisD以上都不对10设有如下代码:1. class Example2. String str;3. Example()4. str= example;5. 6. Example(String s)7. str=s;8. 9. 10. class Demo extends Example11. 12. public class Test13. public void f () 14. Example ex = new Example(Good);15.

7、Demo d = new Demo(Good);16. 17. 以下哪行将导致错误( D )。 A第3行 B第6行 C第10行 D第15行 11在Java中,如下的修饰符不是访问控制修饰符( A )。Astatic Bpublic Cprotected Dprivate12试完成下述程序片段( D )。public class Pointint x,y;public Point(int x,int y)( )=x; ( )=y; . APoint.x Point.y B无解Cx1 y1Dthis.x this.y13在JAVA 中( C )。A一个子类可以有多个父类,一个父类也可以有多个子类B

8、一个子类可以有多个父类,但一个父类只可以有一个子类C一个子类只可以有一个父类,但一个父类可以有多个子类D上述说法都不对14什么是在子类中创建一个和父类具有一样特征的方法,特征包括方法名字,参数个数,参数类型和方法返回值类型( A )。A覆盖(overloading) B重载(overriding) C继承(inheritance) Dnone15哪个关键词在子类中用来访问与父类中一样的方法( A )。Asuper Bthis Cstatic D以上没有16哪个关键词用来引用当前类的对象( B )。Asuper Bthis Cstatic D以上没有17哪个修饰符定义的方法和变量只在定义它们的类

9、中可见,而在其他的任何类中它们都不可见( C )。Aprotected Bpublic Cprivate Dnone of the above18 1. class Person 2. public void printValue(int i, int j) /. 3. public void printValue(int i)/. 4. 5. public class Teacher extends Person 6. public void printValue() /. 7. public void printValue(int i) /.8. public static void ma

10、in(String args)9. Person t = new Teacher();10. t.printValue(10);11. 12. 第10行将调用的会是哪个方法( D )。Aon line 2 Bon line 3 Con line 6 Don line 719以下代码运行结果是( C )。class Base class Sub extends Base class Sub2 extends Base class CEx public static void main(String argv) Base b = new Base(); Sub s = (Sub) b; A编译通过

11、 B编译错误 C运行异常 D以上都不对20设有如下类定义: class BaseWidget String name=BaseWidget; void speak()System.out.println(I am a +name); class TypeAWidget extends BaseWidget TypeAWidget()name=TypeA; 以下哪段代码将正确编译和执行( B )。AObject a=new BaseWidget(); a.speak();BBaseWidget b=new TypeAWidget(); b.speak();CTypeAWidget c=new B

12、aseWidget(); c.speak();D以上都不对21设有文件Derived.java中代码如下.public class Base extends Object String objType; public Base() objType=I am a Base type; public class Derived extends Base public Derived() objType=I am a Derived type; public static void main(String args) Derived D=new Derived(); 编译程序将出现何问题( B )。

13、A将创建 Base.class 和 Derived.class 两个文件B编译程序将指示第1行有问题C编译程序将在第7行出错D以上都不对22哪种访问组合可放在第3行aMethod前和第8行的aMethod前( C )。 1. class SuperDuper 2. 3. void aMethod() 4. 5. 6. class Sub extends SuperDuper 7. 8. void aMethod() 9. Aline 3: public; line 8: privateBline 3: protected; line 8: privateCline 3: private; li

14、ne 8: protected Dline 3: public; line 8: protected23以下类: 1. public class Base 2. public void method(int i) 3. System.out.print( Value is + i); 4. 5. 1. class Sub extends Base 2. public void method (int j) 3. System.out.print( This value is + j); 4. 5. public void method(String s) 6. System.out.print

15、(I was passed + s); 7. 8. public static void mainString args) 9. Base bl = new Base(); 10. Base b2 = new Sub(); 11. bl . method (5); 12. b2 . method (6); 13. 14. Sub类的main方法的执行结果为( C )。AValue is 5Value is 6BThis value is 5This value is 6CValue is 5This value is 6DThis value is 5Value is 624下列程序的运行的结

16、果是( A )。class parent void test() System.out.print(parent);public class child extends parent void test() super.test(); System.out.print( child);public static void main(String args) child x=new child(); x.test();Aparent child Bchild Cparent Dchild parent 25下列程序的运行的结果是( D )。class parentparent(String s)

17、 s=parent; void test() System.out.print(parent);public class child extends parent void test() super.test(); System.out.print( child);public static void main(String args) child x=new child(); x.test();Aparent child Bchild Cparent D编译错误26下列程序的运行的结果是( D )。class parentparent(String s) s=parent; void tes

18、t() System.out.print(parent); public class child extends parent child(String s) s=child;void test() super.test(); System.out.print( child);public static void main(String args) child x=new child(); x.test();Aparent child Bchild Cparent D编译错误27看下列程序package a;class parent private int i=20; protected in

19、t j=30; public int k=40; int h=50;class child extends parent void f() 在子类child的方法f()中不可以操作的变量是( A )。Ai Bj Ck Dh28看下列程序package a;public class parentprivate int i=20;protected int j=30;public int k=40;int h=50;package b;import a.parent;class child extends parent void f() 在子类child的方法f(A)中不可以操作的变量是( D )

20、。Ai Bj Ck Dh29看下列程序package a;class parentprivate int i=20;protected int j=30;public int k=40;int h=50;class child1 extends parent class child2 extends child1 void f() 在子类child2的方法f()中不可以操作的变量是( A )。Ai Bj Ck Dh30如下类的声明: class A 则类A的父类是( C )。A没有父类 B本身 CObject DLang31下列程序的运行结果是(C )。class parent int i=2

21、0; int j=30; void f() System.out.print( +i); class child extends parent int i=30; int k=40; void f() System.out.print( +i); void g() System.out.print( +k); public static void main(String args) parent x=new child(); System.out.print(x.i); x.f(); child x1=(child)x; System.out.print( +x1.i); x1.f(); A3

22、0 30 30 30 B20 20 20 20 C20 30 30 30 D都不对32什么样的方法不能被重写( B )。A私有方法B最终方法(final方法)C受保护的方法D都不对33如果一个成员变量声明时必须赋给初值,而且不能再发生变化,那么这个成员变量是( B )。A私有变量B最终变量(常量)C受保护的变量D都不对34关于重载和重写的叙述正确的是( D)。A重载是多态的一种,而重写不是B重载是子类中定义的方法和父类中某个方法相同C重写是一个类中多个同名的方法,并且方法的参数不同D重写方法时不允许降低方法的访问权限二编程题1 创建2个包:a和b。在包a中编写一个公共类A,类A中有:2个pub

23、lic double类型的属性c、d;一个构造方法public A(double x,double y)对c,d进行初始化;还有一个方法public double add()返回c与d的和。在包b中编写一个主类B,在类B的main方法中创建类A的对象e,并用对象e调用方法add求2个数的和。1package a; public class A public double c,d; public A(double x, double y) c = x; d = y; public double add() return c+d; package b;import a.A;class B publ

24、ic static void main(String args) A e = new A(1,2) System.out.println(两个数之和: + e.add(); 2. 编写一个类A,该类创建的对象可以调用方法f输出小写的英文字母表。然后再编写一个A类的子类B,要求子类B必须继承A类的方法f(不允许重写),子类B创建的对象不仅可以调用方法f输出小写的英文字母表,而且可以调用子类新增的方法g输出大写的英文字母表。最后编写主类C,在主类的main方法中测试类A与类B。2class A void f() System.out.println(A输出小写的英文字母表:); char c; f

25、or(c=a;c=z;c+) System.out.print( +c); System.out.println(); class B extends A void g() char c; System.out.println(B输出大写的英文字母表:); for(c=A; c=Z; c+) System.out.print( +c); System.out.println(); class C public static void main(String args) A a = new A(); B b=new B(); a.f(); b.f(); b.g(); 3编写一个Java应用程序,

26、该程序包括3个类: A类、B类和主类E。其中类B是类A的子类,在子类B中新增了成员变量和成员方法,并且隐藏了父类A的成员变量和重写了父类A的成员方法。在主类E的main方法中,创建类B的对象并赋给父类A的对象a,使用上转型对象a来测试上转型对象的一些特性。3class A int i=1; int j=10; void a() System.out.println(a of A); void b() System.out.println(b of A); class B extends A int j = 20; int k =200; void b() System.out.println(

27、b of B); void c() System.out.println(c of B); class E public static void main(String args) A a = new B(); System.out.println(a.i= + a.i); /extends System.out.println(a.j= + a.j); /隐藏 a.a(); /extends a.b(); /重写 4编写一个Java应用程序,该程序包括3个类:类人猿类、People类和主类E。要求:1)类人猿中有个构造方法:类人猿(String s),并且有个public void speak()方法,在speak方法中输出“咿咿呀呀.”的信息。2)People类是类人猿的子类,在People

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

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