收藏 分享(赏)

软件学院_面向对象程序设计_2008-2009(2)期末B卷.doc

上传人:HR专家 文档编号:11447233 上传时间:2020-04-29 格式:DOC 页数:12 大小:130.51KB
下载 相关 举报
软件学院_面向对象程序设计_2008-2009(2)期末B卷.doc_第1页
第1页 / 共12页
软件学院_面向对象程序设计_2008-2009(2)期末B卷.doc_第2页
第2页 / 共12页
软件学院_面向对象程序设计_2008-2009(2)期末B卷.doc_第3页
第3页 / 共12页
软件学院_面向对象程序设计_2008-2009(2)期末B卷.doc_第4页
第4页 / 共12页
软件学院_面向对象程序设计_2008-2009(2)期末B卷.doc_第5页
第5页 / 共12页
点击查看更多>>
资源描述

1、一、 选择题(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 package is a collection of related Java source program.C.Using the import statement can include a

2、ll 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 statement about Java constructors?A.The name of a constructor must be the same as its classs name.B.A c

3、onstructor has no return value and can not be modified by void.C.A constructor of the parent class can not be inherited by its sub-classes.D.All constructors must be modified by public.3 Giving the code bellow:class Test private int m; public static void fun() /* some code. */ How to make the member

4、 variable m accessible for method fun()?A.change private int m to protected int mB.change private int m to public int mC.change private int m to static int mD.change private int m to int m4 Which of the following functions is an overloading function of public void example().?A.public void example().

5、B.public int example().C.public void example2().D.public int example(int m, float f).5 In Java, 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 fea

6、ture in terms of object-oriented programming?A.HidingB.OverridingC.OverloadingD.This feature is not supported in Java6 How to execute the following program?public class Test public static void main(String args) System.out.println(args0); A.java Test.classB.java TestC.java Test aStringD.javac Test7 I

7、f a container has been resized, which of the following layout manager did not change the internal 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” s

8、tatement catches exception by type-matching.C.In the “try-catch-finally” structure, the 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 va

9、riable of a class can only be assigned to an object of its first level sub-classes of this class.B.An object can not be casted to the type of another class which has no inheritance relationship with the objects original class.C.A child classs reference variable can be assigned to an object of its pa

10、rent class.D.There is only explicit casting, but no implicit casting.10 Both class Teacher and Student are the sub-classes of Person.Person p; Teacher t; Student s; / assume p, t and s are not nullif(t instanceof Person) s = (Student)t; Which statement about the last line of expression is correct?A.

11、A new Student object will be created.B.The type-casting is correct.C.The 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.pr

12、intln(o); A.Generates compile error.B.Compiles OK, but has runtime errors.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 = s1.intern();String s3 = Hello;A.s1 = sB.s2 = sC.s = s3D.s2 = s313 T

13、he array definition code is given below, which statement is correct?String s = new String10;A.The definition of array s is illegal in syntax.B.s is a 1010 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

14、?public static 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 is two15 The file “emp

15、ty.txt” does not exist before, what its content will be after executing the following code.public static void main(String args) throws FileNotFoundException PrintWriter pr = new PrintWriter(new File(empty.txt); pr.print(onettwo); pr.append(n1t2); pr.close();A.one twoB.onettwo1 21t2C.onettwon1t2D.one

16、 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 m() public void p() class Beta extends Alpha public

17、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 increase() value += 1; 三、 程序阅读题(20分)说明:阅读下面程序并写出它们的输出结果,每小题5分

18、。1 The program is as below:class A int 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() System.out.println(What a pleasure!); public Base(String s)

19、 this(); System.out.println(I am + s + !); public class Child extends Base public static void main(String args) Child t = new Child(Mike); public Child(String s) super(s); System.out.println(How do you do?); public Child() this(I am Tom); 3 The program is as below:class DivTest public static void ma

20、in(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!); finally System.out.println(Calculation complete!); System.out.println(Program finish!); 4 Analyze the program bellow, and explain its effect.pu

21、blic class MyFrame extends JFrame JButton b1, b2; public MyFrame() ActionListener a = new ActionListener() public void actionPerformed(ActionEvent evt) if (evt.getSource() = b1) b1.setEnabled(false); b2.setEnabled(true); else b1.setEnabled(true); b2.setEnabled(false); ; setLayout(new FlowLayout(); b

22、1 = new JButton(1); b1.addActionListener(a); add(b1); b2 = new JButton(2); b2.addActionListener(a); add(b2); setDefaultCloseOperation(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 cl

23、asses founded in a companys personnel management system, find out their relationships and illustrate using a UML class diagram.Employee, long-tern employee, temporal employee, manager, temporal salesman.五、 程序设计题(24分)说明:按照题目要求编写下面两段程序。1 Write a java application program containing these classes: Perso

24、n, Student, TestStudent. The details are:Class PersonPropertiesname: Stringsex: charid: Stringphone: Stringemail: String MethodsPerson(Name name, char sex, String id): constructorString getId()void setEmail(String email)void setPhone(String phone)String toString(): outputs a persons informationClass

25、 StudentA sub-class derived from Person, more properties are added:PropertiessNo: longsClass: StringMethodsStudent(long sNo, String name, char sex, String id): constructorsetClass(String sClass)String toString(): outputs a students informationClass TestStudentA class used as the main class to test t

26、he functions.use the following information to create a student object, aStudent.Name: Guo Yang Sex: male ID: 22033198807070333 sNo.: 2004002 set other information to aStudent.E-mail: Phone: 88078549 output all the information of aStudent.2 Calculate the sum area of circles. (14 points)The requireme

27、nts are: Define an interface Shape, and a no-arg method getArea() that returns double value. Define a class Circle implementing the Shape interface above, within the class there is a double property radius and two constructors. One of the constructors has no argument and it sets the radius to zero;

28、another constructor sets the radius by using the argument provided, or sets radius to zero when the argument is less than zero. Write a class Test containing the main method that converts each command-line argument to double values, and create Circle objects according to the double values converted. Exception handling should be provided on conversing the command-line arguments. If an error occurred, print an error message and create the Circle using the default constructor. Finally, calculate and output the sum area of all the Circles.第 12 页 共 12 页

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 学术论文 > 管理论文

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报