抽象类和接口测试题_第1页
抽象类和接口测试题_第2页
抽象类和接口测试题_第3页
抽象类和接口测试题_第4页
抽象类和接口测试题_第5页
免费预览已结束,剩余4页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精品文档、选择题(每题2分,共20分)1 . Java中用来实现继承的关键字是 AextendsB、implementsGpublicDkprotected2 .如果要用到一个接口的关键字是 A、importB、implementsGextendsDkfinal3 .接口是Java面向对象的实现机制之一,以下说法正确的是A Java支持多重继承,一个类可以实现多个接口B Java只支持单重继承,一个类可以实现多个接口C Java只支持单重继承,一个类只可以实现一个接口D Java支持多重继承,但一个类只可以实现一个接口4 .请分析以下代码,请问下面 不可以产生 Q8对象?public clas

2、s Q8public Q8(int i)public Q8(int i,float f)A Q8 q=new Q8();B> Q8 q=new Q8(10);C Q8 q=new Q8(10,10f);D 以上方法均不可以5 .设有下面两个类的定义:class Person long id;String name;Class Student extends Personint scroe;int getScore() 则类Student和类Person的关系是 A包含关系 B、继承关系-C1关联关系D上述类定义有语法错误7 . 类是JAVA语言中所有类的父类。A classB、java.

3、langC ObjectD 以上都不正确8 .下列关于抽象类描述正确的是有问题A、某个抽象类的父类是抽象类,则这个类必须要重写父类中的所有抽象方法 日接口和抽象类是一回事C可以使用抽象类去创建对象 DK抽象类中不可以有非抽象方法 10.下面的程序输出的结果是 public class A implements B int k=20;public static void main(String args口)int i;B c1 = new A();i= c1.k;System.out.println("i="+i);interface B int k = 10;程序有编译错误

4、D) i=trueA) i=20B) i=10 C) 二、填空题(每空1分,共10分)1 .如果子类中的某个变量的变量名与它的父类中的某个变量完全一样,则称子类中的 这个变量?了父类的同名变量。2 .属性的隐藏是指子类重新定义从父类继承来的 ?。3 .如果子类中的某个方法的名字、返回值类型和 参数 与它的父类中的某个方法完全一样,则称子类中的这个方法覆盖了父类的同名方法。4 . Java 仅支持类间的_单_重继承。5 .抽象方法只有方法头,没有方法体。6 . Java 语言的接口是特殊的类,其中包含 public/static/finnal (静态)常量和 public/abstract( 抽

5、象)方法。7 .接口中所有属性默认修饰符均为_public_、_static_ 和 finnal 的。三、程序填空题(每空 2分,共10分)1 .下面是一个类的定义,完成程序填空。public class Youwrite int x;( ) x=0;2 .下面是定义一个接口ITF的程序,完成程序填空。public interfaceITFpublic static final double PI=Math.PI;public _abstract double area(double a, double b);3 .下面是定义一个接口A的程序,完成程序填空。public interface A

6、public static finnal double PI=3.14159;public abstract double area(double a, double b)_;四、程序阅读题(每题 5分,共30分)1 .现有类说明如下,请回答问题:public class AString str1=" Hello! t"String str2=" How are you?"public String toString() return str1+str2; public class B extends A String str1="bb, Bi

7、ll."public String toString() return super.str1+str1; 问题:1)类A和类B是什么关系?继承(父子)这种现象分别称为什么?覆盖2)类A和类B都定义了 str1属性和方法toString()1欢立下载精品文档(重写)3)若a是类A的对象,则a.toString()的返回值是什么?A How are you?4)若b是类B的对象,则b.toString()的返回值是什么?B super2 .现有一个类定义如下,请回答问题:class EmployeeString name;int age;double wage;static int No

8、=0;Employee(String a1,int a2,double a3) name=a1; age=a2; wage=a3;No+;在使用t类时,已使用下面语句生成了该类的对象 :Employee e1,e2;e1=new Employee。'王劲”,26,6300);e2=new Employee。'张山",30,3800);问题:1),e2.age,e2.wage 的值各是什么?张山,30,38002)生成对象el、e2后,e1.No值为多少?能否通过类名做前缀引用属性No?2 可以3 .阅读程序,回答问题。 public class Inhe

9、ritTestlpublic static void main (String口 args) A aa; B bb;aa=new A( ); bb=new B();aa.show( ); bb.show();class Aint a=1;double d=2.0;void show() System.out.println("Class A: "+"ta="+a +"td="+d); class B extends A float a=3.0f;String d="Java program."int b=4;voi

10、d show() System.out.println("Class A: "+"ta="+super.a +"td="+super.d);super.show();System.out.println("Class B: "+"ta="+a +"td="+d+"tb="+b);3欢立下载精品文档问题:1)类A和类B是什么关系?2)按程序输出的格式写出程序运行后的结果.4 . 有如下源程序,请回答问题: class AString s="clas

11、s A" class B extends A String s="class B" public class TypeConvert public static void main(String args) B b1,b2=new B();A a1,a2;a1=(A)b2;a2=b2;System.out.println(a1.s);System.out.println(a2.s);b1=(B)a1;System.out.println(b1.s);System.out.println(b2.s);问题 : 该程序的四行输出各是什么?5 .运行类C的输出结果是什么

12、?class Apublic A() System.out.println(“The default constructor of A is invoked”); class B extends A public B() public class Cpublic static void main(String args) B b = new B();6 . 阅读下列程序写出输出结果:class A String s="class A"void show()# 欢迎下载 。精品文档System.out.println(s);class B extends A String s

13、="class B"void show()System.out.println(s);public class TypeConvertpublic static void main(String args)B b1;B b2=new B();A a1,a2;a1=(A)b2;a2=b2;System.out.println(a1.s);a1.show();System.out.println(a2.s);a2.show();b1=(B)a1;System.out.println(b1.s);b1.show();System.out.println(b2.s);b2.show

14、();五、写出程序运行结果(每题5 分,共 30 分)1. class TestTest()System.out.println("Test");class Demo extends TestDemo()System.out.println("Demo");public static void main(String args)new Demo();new Test();2. interface Aclass B implements Apublic String func() return "func"class Demo publ

15、ic static void main(String口 args) A a=new B();System.out.println(a.func();3. class Fu boolean show(char a) System.out.println(a); return true;class Demo extends Fupublic static void main(String口 args)int i=0;Fu f=new Demo();Demo d=new Demo();for(f.show('A'); f.show('B')&&(i&l

16、t;2);f.show('C')i+; d.show('D');boolean show(char a)System.out.println(a); return false;4. interface Aclass B implements Apublic String test()return "yes"class Demostatic A get()return new B();public static void main(String args) A a=get();System.out.println(a.test();5. cla

17、ss Superint i=0;public Super(String a)System.out.println("A");i=1;public Super()System.out.println("B");i+=2;class Demo extends Superpublic Demo(String a)System.out.println("C");i=5;public static void main(String args) int i=4;Super d=new Demo("A");System.out.println(d.i);7 欢迎下载 。精品文档6. class Fuint num=4;void show()System.out.println("showFu");class Zi extend

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论