下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、.华南农业大学期末考试试卷( B卷)2008-2009学年第 2 学期考试科目:面向对象程序设计考试类型:(闭卷)考试时间:120分钟学号姓名年级专业_题号一二三四五总分得分评阅人一、选择题( 30分)说明:每题2 分,只有1 个正确答案,请将正确答案填写在下面表格中。题号123456789101112131415答案1 Which of the following statements is correct about Java packages?A. A package may contain unlimited number of nested sub-packages.B. A pac
2、kage is a collection of related Java source program.C. Using the import statement can include all the classes into the current program from a specified package and its sub-packages.D. If there is no package statement used, the current class will not be in any package. 2 Which one is the wrong statem
3、ent about Java constructors?A.The name of a constructor must be the same as its classs name.B.A constructor has no return value and can not be modified byvoid .C. A constructor of the parent class can not be inherited by its sub-classes.D. All constructors must be modified bypublic.3 Giving the code
4、 bellow:class Testprivate int m;public static void fun() /* some code. */ How to make the member variable maccessible for method fun()?A.change "private int m" to " protected int m"B.change "private int m" to " public int m".C. change "private int m"
5、 to " static int m"D. change "private int m" to " int m "4 Whichofthefollowingfunctionsisanoverloadingfunctionof" publicvoidexample()."?A. public void example().B. public int example().C. public void example2().D. public int example(int m, float f).5 In Java,
6、a class may have many different methods with the same name. The number, type,sequences of arguments in these methods are different, and the return value can be different as well. What do we call this feature in terms of object-oriented programming?A.HidingB.OverridingC. OverloadingD. This feature is
7、 not supported in Java6 How to execute the following program?public class Testpublic static void main(String args) System.out.println(args0);A.java Test.classB.java TestC. java Test aStringD. javac Test7 If a container has been resized, which of the following layout manager did not change the intern
8、al components' size?A.CardLayoutB.FlowLayoutC. BorderLayoutD. GridLayout8 Which is the right statement about exception handling?A. In java, all exceptions are necessary to be caught and handled.B. The “catch ”statement catches exception by type-matching.C. In the “try-catch-finally ”structure, t
9、he program will exit after exception handling.D. Exception is a kind of errors, and it should be absolutely avoided in programs.9 The following statements are about type-casting, which one is correct?A. A reference variable of a class can only be assigned to an object of its first level sub-classes
10、of this class.B. An object can not be casted to the type of another class which has no inheritance.relationship with the object s original class.C. A child class s reference variable can be assigned to an object of its parent class.D. There is only explicit casting, but no implicit casting.10 Both c
11、lass Teacher and Student are the sub-classes of Person . Person p; Teacher t; Student s; / assume p, t and s are not null if(t instanceof Person) s = (Student)t; Which statement about the last line of expression is correct?A. A new Student object will be created.B. The type-casting is correct.C. The
12、 expression is incorrect.D. There is no syntax error but will generate runtime error.11 According to the code below, which statement is correct?public class Test static Object o;public static void main(String args) System.out.println(o);A. Generates compile error.B. Compiles OK, but has runtime erro
13、rs.C. Outputs zero.D. Outputs “null ”.12 According to the code below, select the statement which is false.String s = "Hello"String s1 = new String("Hello");String s2 = ern();String s3 = "Hello"A.s1 = sB.s2= sC.s = s3D.s2= s313 The array definition code is given be
14、low, which statement is correct?String s = new String10;A.The definition of arrays is illegal in syntax.B. s is a 10 10×two-dimensional array.C. All elements in s are "" .D. s is an array of ten arrays.14 Which is the correct output according to the program given bellow?public static
15、void main(String args)Scanner scanner = new Scanner("this is one that is two"); scanner.useDelimiter(" is"); / there is a space before "is".while(scanner.hasNext() System.out.print(scanner.next();A.this one that twoB.th one that twoC. thone that twoD. this is one that i
16、s two15 The file “empty.txt”does not exist before, what its content will be after executing thefollowing code.public static void main(String args) throws FileNotFoundException PrintWriter pr = new PrintWriter(new File("empty.txt");pr.print("onettwo");pr.append("n1t2");p
17、r.close();A.one twoB.onettwo121t2C. onettwon1t2D. one two 1 2二、改错题(20 分)说明:写出每段代码的错误原因并改正错误,每小题4 分,说明原因和改正各2 分。1 class First import java.io.*;package mypackage;class Second 2 class A String name;public A(String s) name = s; class B extends A int id;public B (int i) id = i; 3 class Alpha private void
18、 m() .public void p() class Beta extends Alpha public void m() private void p() 4 interface Base void m();void n();class Child implements Base public void m() System.out.println("this is method m");5 public class B extends A final void increase() value += 2;class A int value = 0;final void
19、 increase() value += 1;三、程序阅读题(20 分)说明:阅读下面程序并写出它们的输出结果,每小题5 分。1 The program is as below:.class Aint h = 1;public A(int h)h = h;System.out.println(this.h);this.h = h;System.out.println(this.h);public static void main(String args)A a = new A(2);2 The program is as below:class Base public Base() Syste
20、m.out.println("What a pleasure!");public Base(String s) this();System.out.println("I am " + s + "!");public class Child extends Basepublic static void main(String args) Child t = new Child("Mike");public Child(String s) super(s);System.out.println("How do
21、 you do?");public Child() this("I am Tom");.3 The program is as below:class DivTest public static void main(String args) int r, n, d;n = 10; d = 0;try r = n / d;System.out.println("r=" + r); catch(ArithmeticException e) System.out.println("Divide 0 exception!"); fi
22、nally System.out.println("Calculation complete!");System.out.println("Program finish!");4 Analyze the program bellow, and explain its effect.public class MyFrame extends JFrame JButton b1, b2;public MyFrame() ActionListener a = new ActionListener() public void actionPerformed(Act
23、ionEvent evt) if (evt.getSource() = b1) b1.setEnabled(false);b2.setEnabled(true); else b1.setEnabled(true);b2.setEnabled(false);setLayout(new FlowLayout();b1 = new JButton("1"); b1.addActionListener(a); add(b1);b2 = new JButton("2"); b2.addActionListener(a); add(b2); setDefaultCl
24、oseOperation(JFrame.EXIT_ON_CLOSE);.setSize(150, 100);setVisible(true);public static void main(String args) new MyFrame();四、应用设计题(6 分)The following classes are a part of the classes founded in a companys personnel management system, find out their relationships and illustrate using a UML class diagr
25、am.Employee, long-tern employee, temporal employee, manager, temporal salesman.五、程序设计题(24 分)说明:按照题目要求编写下面两段程序。1Write a java application program containing these classes:Person , Student , TestStudent.The details are: Class Person Properties name: String sex: charid : Stringphone: Stringemail : Strin
26、g MethodsPerson(Name name, char sex, String id): constructorString getId()void setEmail(String email)void setPhone(String phone)String toString(): outputs a persons informationClass StudentA sub-class derived from Person, more properties are added:PropertiessNo: longsClass : StringMethodsStudent(lon
27、g sNo, String name, char sex, String id): constructorsetClass(String sClass)String toString(): outputs a students information Class TestStudentA class used as the main class to test the functions.use the following information to create a student object,aStudent .Name:Guo YangSex:maleID:22033198807070333sNo.:2004002 set other information to aStudent . E-mail: yangguoPhone:88078549output all the informa
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年四川旅投教育投资有限责任公司公开招聘备考题库及参考答案详解
- 湛江市2025年事业单位公开招聘高层次人才备考题库及答案详解参考
- 2025年玉溪易门县华亿投资有限责任公司公开招聘工作人员的备考题库及完整答案详解1套
- 2025年云南富宁县紧密型医共体洞波中心分院面向社会公开招聘编外专业技术人员7人备考题库及答案详解一套
- 2025年南宁市武鸣区府城中心卫生院公开招聘编外工作人员备考题库完整答案详解
- 理疗瑜伽课件
- 班级课件刮奖
- 社会消防安全应急演练
- 自动化组长面试技巧
- 化学类专业就业前景指南
- 行政案例分析-终结性考核-国开(SC)-参考资料
- 北京市海淀区2023-2024学年四年级上学期语文期末试卷(含答案)
- 华北战记-在中国发生的真实的战争-桑岛节郎著
- 04S519小型排水构筑物(含隔油池)图集
- 排涝泵站重建工程安全生产施工方案
- (高清版)JTG 3363-2019 公路桥涵地基与基础设计规范
- 2024高考二模模拟训练数学试卷(原卷版)
- 增值税销售货物或者提供应税劳务清单(模板)
- 35770-2022合规管理体系-要求及使用指南标准及内审员培训教材
- 2022年福建翔安区社区专职工作者招聘考试真题
- 四川省成都市青羊区2023年九年级一诊英语试卷
评论
0/150
提交评论