面向对象程序的设计复习题与参考答案C资料

上传人:资**** 文档编号:367952980 上传时间:2023-11-15 格式:DOCX 页数:11 大小:132.63KB
返回 下载 相关 举报
面向对象程序的设计复习题与参考答案C资料_第1页
第1页 / 共11页
面向对象程序的设计复习题与参考答案C资料_第2页
第2页 / 共11页
面向对象程序的设计复习题与参考答案C资料_第3页
第3页 / 共11页
面向对象程序的设计复习题与参考答案C资料_第4页
第4页 / 共11页
面向对象程序的设计复习题与参考答案C资料_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《面向对象程序的设计复习题与参考答案C资料》由会员分享,可在线阅读,更多相关《面向对象程序的设计复习题与参考答案C资料(11页珍藏版)》请在金锄头文库上搜索。

1、ti=10;classTesterpublicstaticvoidtest(intx)x=20pYearpublicbooleancomputeLeapYear(intyear)if(yeasabicycle.xxxxalsoownsabicycle.四、编程题:1.importjavax2550751001254.The1stlineofmain()The2ndlineofmain().网络教育课程考试复习题及参考答案面向对象程序设计一、填空题:1. 创建类的对象时,使用运算符_给对象分配存空间。2.Java 通过来区分重载函数。3. 在子类中使用保留字_ _ 可调用被子类覆盖的父类中的方法

2、。4. 使用保留字可以从一个构造方法中调用同一个类的另一个构造方法。5. 抽象类用修饰符定义。6. 类的数据成员的访问权限修饰符一般为7. 访问权限修饰符按照访问权限的大小从大到小分别为、。8. 定义类的构造方法不能有 ,其名称与 名相同。9. 抽象方法是的特征是。10.Java 中的所有异常都是从 继承来的。11. 对象引用中存储的容是。12. 下列程序段执行后,String str1 = new String(Java);String str2 = new String(Java);if (str1.equals(str2) System.out.println(They are equa

3、l); else System.out.println(They are not equal);输出结果为: 。13. 下面循环执行后的 sun 值为 int count =0, sum = 0;while ( count 10 ) sum += count;count +;14.Java 语言中关键字_ _ 表示双精度类型。15. 保留字_ _ 用于导入包中的类到程序中,供程序中使用。 16.Java 语言中继承是用保留字表示。17. 面向对象程序设计中,类是指。18. 对象包含和。19. 若有类定义:class B extends A则类 B是类 A的_。20.Java 语言中, 通常把可

4、能发生异常的方法调用语句放到try 块中, 并用紧跟其后的_块来捕 获和处理异常。21. 多态是指。22. 声明常量时使用修饰符。 23.Java 中异常抛出使用保留字。24. 一个类成员或者方法前面加上了修饰符, 那说明该数据成员和方法可以直接通过类名 来访问和调用。. . .OwnerName()+alsoownsabicycle.);classBicycleprRock(i);lassBicycleRegistrationpublicstaticvoidintcount=1;count=30;count+=3)sum+=count;.7.Jlineofmain();输出结果为:5.imp

5、ortjava.io.*;classBase.25. 如果类成员前面没有访问权限修饰符,则该类成员具有访问权限。26. 下面构造方法是非法的 a):public int ClassA(int one)b):public ClassB(int one,int two)c) :ClassC()27. 程序填空:public void getData() String str = JoptionPane.showInputDialog(null,if (str.equals( “”)throw new IOException();)”Input: ”);28. 对象称为类的。29.Java 程序的源

6、文件以为扩展名,编译后的文件以为扩展名。二、简答题:1. 类和对象的概念和关系是什么?2. 请说明对象声明和对象生成之间的区别,并使用存状态图举例说明这种区别。 3.this 和 super 两个保留字的意义和作用是?4. 构造器方法有什么特点和作用?5. 保留字 throw 和 throws 有什么区别?6. 将下面的 while 循环改写为 for 循环int count =1, sum = 0;while ( count = 30 ) sum += count;count +=3;7.Java 语言编译和执行的过程是?8. 检查型异常和非检查型异常有何区别?9. 请改造下面的构造方法,使

7、第一个构造方法调用第二个构造方法。 public ClassOne(int alpha) this.alpha = alpha;this.beta = 0;public ClassOne(int alpha , int beta) this.alpha = alpha;this.beta = beta;10.Java 有哪几个访问权限修饰符,各起到什么作用?. . .ut.println(Theyareequal);elseSystem.out.printl.throw用于抛出一个异常,throws则是用于声明未必处理的运行时异常。6.sum=0;for(该成员变量和方法是共有的,能在任何情况

8、下被访问。protected:必须在同一包中或者该类的导出类中ar();System.out.println(puteLeapYear(1998);.11. 请说明实例方法、类方法和构造器方法的特点和区别。三、请写出下面的代码段的输出结果: 1.class Q2mainpublic static void main(string args) QuestionTwo q2;q2= new QuestionTwo();q2.init();q2.increment();q2.increment();system.out.println(q2.getCount();class QuestionTwop

9、rivate int count;public void int()count=1;public void increment()count=count+1;public int getCount()return count;2.int gradeLevel;switch (gradeLevel) case 1:System.out.print(Go to the 101);case 2:System.out.print(Go to 202);break;case 3:System.out.print(Go to 303);case 4:System.out.print(Go to 404);

10、break;default:System.out.print(default);如果变量 gradeLevel 在 switch 语句之前为以下数值,上述程序代码段执行后,将分别输出什么?a) 2b) 3c) 4d) 53.int x;for (int width = 1; width =20, width+)for (int length = 5, length =25, length+=5). . .eofmain()The5thlineofmain()5.Base()defaultDerived();q2.init();q2.increment();q2.increment();syst

11、em.o.实例1.对象是系统中用来描述客观事物的一个实体,它是构成系统的一个基本单位。一个对象由一组属性和对Derived();Derived(Stringss)System.out.println.x = width * length;System.out.print ( + x);System.out.println();输出结果为:4.class MyException1 extends Exception public MyException1() public MyException1(String msg) super(msg); public class ExceptionTes

12、tpublic static void f() throws MyException1 System.out.println(The 1st line of f();throw new MyException1(Exception1:Originated in f();public static void main(String args) System.out.println(The 1st line of main();try System.out.println(The 2nd line of main();f();System.out.println(The 3rd line of m

13、ain();catch(MyException1 e) System.out.println(e.getMessage();finally System.out.println(The 4th line of main();System.out.println(The 5th line of main();输出结果为:5.import java.io.*;class BaseBase()System.out.println(Base();void m1()System.out.println(Base.m1();class Derived extends BaseDerived()this(default);System.out.println(Derived();Derived(String ss)System.out.println(ss);. . .ringargs)Weightw1=newWeight();System.out.printltendsShapevoiddraw()System.out.println(Square.dBaseDerived()this(default);System.out.println(.void m1()System.out.prin

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号