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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

本文(面向对象程序设计复习题与参考答案Word文档格式.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

面向对象程序设计复习题与参考答案Word文档格式.docx

1、则类B是类A的_。20Java语言中,通常把可能发生异常的方法调用语句放到try块中.并用紧跟其后的_块来捕获和处理异 常。21多态是指。22声明常量时使用修饰符。23.Java中异常抛出使用保留字。24个类成员或者方法前面加上了修饰符,那说明该数据成员和方法可以直接通过类需来访问和调用。 25如果类成员前而没有访问权限修饰符,则该类成员具有访问权限。26.卜而构造方法是非法的 a):public int ClassA(int one) b):public ClassB(int one,int tv/o)c): ClassC()27程序填空:public void getData() Stri

2、ng str = JoptionPane.shov/lnputDialog(null/,lnput:M); if (str.equals(“”) throw new IOException();)2&对象称为类的。29.Java程序的源文件以为扩展名,编译后的文件以为扩展夕“二、 简答题:仁类和对象的概念和关系是什么?2请说明对象声明和对象生成之间的区别,并使用内存状态图举例说明这种区别。3.this和super两个保留字的意义和作用是?4 构造器方法有什么特点和作用?5保留字throw和throv/s有什么区别?6将下而的 while 循环改写为 for 循环 int count =1, s

3、um = 0;= 30 ) sum += count; cou nt +=3;7Java语言编译和执行的过程是?检查型异常和非检査型异常有何区别?9请改造下而的构造方法,使第一个构造方法调用第二个构造方法。public ClassOne(int alpha) this.alpha = alpha;this, beta = 0;public ClassOne(int alpha , int beta) this.alpha = alpha;this .beta = beta;10.Java有哪几个访问权限修饰符,各起到什么作用?门请说明实例方法.类方法和构造器方法的特点和区别。三、 请写出下面的

4、代码段的输出结果:1.class Q2mainpublic static void main(string args) Question1vo q2;q2= new Questionlvo();q2.init();q2.increment();system, out. pri ntln(q2getCo un t();class Question17oprivate int count;public void int()count=1;public void increment()coun t=cou nt+1;public int getCount()return count;2.int gr

5、adeLevel;sv/itch (gradeLevel) case 1: System.out.printCGo to the 101case 2:System.out.printCGo to 202”); break;case 3:Go to 303case 4:System.out.printfGo to 404n);break;default:System.out. printCdefauk11);如果变M gradeLevel在switch语句之前为以下数值,上述程序代码段执行后,将分别输出什么?a)2b)3c)4d)53.int x;for (int v/idth = 1; v/i

6、dth =20, v/idth+)for (int length = 5, length =25, length+=5)x = width * length;System.out.print ( + x);System.out.printlnC1);输岀结果为:4.class MyExceptionl extends Exception public MyExceptionl () Qpublic MyExceptionl (String nisg) super(msg); public class Exceptionlestfpublic static void f() throv/s My

7、Exceptiord System. out. print In (HThe 1st line of f()H);throv/ nev/ MyExceptionl (Exception1:Originated in f()public static void main (String args) System. out. pri nt In (The 1st line of main()M);trySystem. out. print In (The 2nd line of main() f();System. out. pri nt In (HThe 3rd line of main() c

8、atch(MyException1 e) System out printin (e getMessage();finally System. out. print In (nThe 4th line of main(门;System.out.printlnCThe 5th line of main()H);输出结果为:5.import java.io.*;class BaseBase()System.out. println(HBaseO,1);void m1()System. out. pri ntln (Base .m1()H);class Derived extends BaseDer

9、ived ()thisCdefault1System.out. pnntln(,Denved()Derived (String ss)System, out. pri ntln(ss);System. out. println (Derived .m1()H);public class Applicationpublic static void main(String args) Base b;b=nev/ Derived();b.m1();6.class Shape void drav()Shape .d rav()H);class Circle extends Shape void dra

10、w() System.out. pnntln(,Circle.drav(),);class Square extends Shape void draw() Systemoutprintln(”Squaredraw()”);public class Shapes public static void main(String args) Shape s = new Shape3;sO=nev/ Shape();s1=nevv Circle();s2二nevv Square()for(int i = 0; i 3; i+)si.draw();7.trynumber = Integer. parse

11、lnt(u-30n);i f (number 0)throw new Exception(“No negative”);catch(NumberFormatException e)System.out.println(“Can not covert to intn);catch (Exception e )System.out.pri ntln (a E rror: +e. getMessage ();finallySystem.out.println(DONEM);class Value int i=10;class 7esterpublic static void test(int x)x

12、=20;public static void test(Value v)v.i =20;Value v仁new Value();int x=10;Tester, test (x);Tester. test(v1);System, out. pri ntln(x);System, out. pri ntln(v1 .i);9.class Rock Rock() System.out.println(Creating Rock11);Rock(int i) System.out.println(”Creating Rock number 11 + i);public class SimpleCon

13、structor if(i=1)new Rock();elsenew Rock;lass BicycleRegistration Bicycle bikel ,bike2;bikel = new Bicycle();bike2= new Bicycle(“xxxx”); bikel .setOv/nerNameCTestSystem.out.println(bikel .getOv/nerName( ) + owns a bicycle.u);System.out.println(bike2.getOv/nerName( ) + M also ov/ns a bicycle.class Bic

14、ycle private String ownerName;public Bicycle( ) ov/nerName = Unknow n”;public Bicycle(String name ) ov/nerName = name;public String getOv/nerName( ) return ov/nerName;public void setOv/nerName(String name) ownerName = name;输岀结果为:4.编程题:1.编写一段Java程序代码,用一个对话在分开的两行中显示两条消息:“I Can Design”和“And I Can Progr

15、am 二2编写一个Java程序,对于给定的年份,回答“Leap Yea严(闰年)或者Not a Leap Year(平年)。 如果一个年份能被4整除,但是不能被100整除,它是闰年;如果一个年份能被100整除,也能被400 整除,它也是闰年。需要定义需为LeapYear的服务提供类3编写一个do-while循环以计算正整数中前30个奇数的累加和。4编写可以根据用户年龄和身髙给出推荐的体重的的Java程序,利用下面的公式计算岀推荐的体重:recommendedWeight = (height - 100 + age/10) *0.9需要左义需为Height (身髙)的服务提供类,它应该会有可以根

16、据身高得到推荐提供的方法。5请按照以下要求写出完整的程序代码(要求能上机编译运行):1) 创建一个抽象类AAbstractBase.该类至少包含一个抽象方法;2) 创建一个类TestClasSt该类继承AAbstractBase,并包含两个构适器方法:6泄义一个Vehicle类,类中包含一个Person类型的数据成员owner、一个获得owner值的访问方法和 一个设It owner值的访问方法。左义VehicleManage个类,该类包含主方法,并在主方法中创建Vehicle 类的对彖,并调用其设置owner和获取owner的方法。参考答案tl3.this它代表当前对象名,可用来调用本类中另

17、一种形成的构造函数(应该为构造函数中的第一条语句), 在程序中易产生二义性之处,应使用this来指明当前对象;super:它引用当前对象的直接父类中的 成员,可以用来调用基类中的某一个构造函数(应该为构造函数中的第一条语句,)也可以用来在基类 与派生类中有相同成员左义时直接访问父类中被隐藏的父类中成员数据或函数。4 构造器一般用于对类进行初始化。其特点如下:a) 其泄义形式跟类中其他方法基本类似b) 英方法名与类名完全相同(包括大小写)。c) 其在对象被创建时自动被Java调用,而无需用户干预d) 其没有返回值类型。e) 一个类可以泄义多个构造方法5.throv/用于抛出一个异常,throws

18、则是用于声明未必处理的运行时异常。6.sum=0;for(int count=1 ;count=30;count+=3)sum+=co unt;7.Java编译器将以.java为后缀需的Java源代码文件编译成以.class结尾的字节码文件。Java的虚拟机再根据不同的软硬件平台将.class文件翻译成机器码文件予以执行。因为编程错误而导致的异常,或者是不能期望程序捕获的异常(解除引用一个空指针,数组越界,除零, 等等),为了使开发人员免于处理这些异常,一些异常被命名为非检査型异常(即那些继承自 RuntimeException的异常)并且不需要进行声明,而检査型异常如果没有捕获则需在方法头部

19、进行声 明。9.public ClassOne(int alpha) this(alpha,O);jpublic ClassOne(int alpha , int beta) 10.public:表明该成员变虽:和方法是共有的,能在任何情况下被访问。protected:必须在同一包中或者 该类的导出类中才能被访问:private:只能在本类中访问;缺省的为包访问权限,在同一个包中可以 访问类方法前而有static保留字,英不需要创建类的实例,通过类名即可访问;实例方法则为普通方法, 其需要创建类的实例后通过实例访问:构造方法的名称与类名完全相同,其在创建类的实例是自动执 行。三.请写出下面的代

20、码段的输出结果:1.32.(a)Go to 202(b)Go to 303Go to 404(c)Go to 404(d)default3.5 10 15 20 2510203040501545607580100251254.The 1st line of main()The 2nd line of main() The 1st line of f()Exception 1:0riginated in f() The 4th line of main()The 5th line of main() 5Base()defaultDerived ()Derived.m1()6.Shape.draw

21、()Circle.drav()Square. drav/()7.Error:No negativeDONE8.109.Creating Rock number 0Creating RockCreating Rock number 210.Test owns a bicyclexxxx also owns a bicycle四、编程题:1.import javax.swing; public class Test JOptionPane.shov/MessageDialogCnuU/l Can DesignnAnd I Can Program2.public class lestpublic s

22、tatic void main(String args)Leap Year ly二n evv LeapY?ar();System.out.println(puteLeapYear(1998);System.out.println(puteLeapYear(1900);System.out. println(puteLeapYear(2000);class LeapYearfpublic boolean computeLeapYear(int year)if (year % 4 = 0 & year % 100 != 0 ) return true;if (year % 100 = 0 & ye

23、ar % 400 = 0 ) return true; return false;3.public class lestpublic static void main (String args)int sum=0,i=0;dosum=(i*2 + 1);i+;v/hile(i=30);System out printl n (sum);4.public class Testpublic static void main(String args) Weight v1 = new Weight。;System.out.println( w1 .getRecommendedWeight(30,170

24、);class Weightypublic double getRecommendedWeight(int age,int height) return (height - 100 + age/10) *0.9;5.public class TestTestclass t1,t2; t1=nev/ TestC lass(); t1.testFun(); t2=nev/ TestC lass (10); t2.testFun();abstract class AAbstractBase abstract void testFun();class TestClass extends AAbstra

25、ctBase int i;7estClass() this(O); 7estClass(int i) this.i=i;void testFun()System out .printl n (i);6.public class VehicleManage public static void main(String args) Vehicle v1 =new Vehicle();Person p1,p2; p仁new Person(); v1.setOv/ner(p1);p2=v1 .getOvner();class VehiclePerson owner;public void setOvner(Person p1) own er=p1;public Person get07ner() return own er;class PersonfString ov/nerName;

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

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