当前位置:首页 >> 其它课程 >>

A卷


华南农业大学期末考试试卷(A 卷)
2011-2012 学年第 2 学期 考试类型: (闭卷)考试 学号


考试科目: 面向对象程序设计 考试时间: 120 分钟 年级专业 二 三 四 总分

姓名 题号 得分 评阅人 一



得分
I.Single choice

(60 points) 1. Which of the following statements compiles OK? A. String #name = "Jane Doe"; B. int $age = 24; C. Double _height = "123.5"; D. double ~temp = 37.5; 2. What are the extension names of Java source file and executable file? A. .java and .exe B. .jar and .class C. .java and .class D. .jar and .exe 3. Given:
10. class CertKiller { 11. static void alpha() { /*more code here*/ } 12. void beta() { /*more code here*/ } 13. }

线

Which statement is wrong? A. CertKiller.beta() is a valid invocation of beta() B. CertKiller.alpha() is a valid invocation of alpha() C. Method beta() can directly call method alpha() D. The method beta() can only be called via references to objects of CertKiller 4. Which method name does not follow the JavaBeans standard on Accessor/Mutator? A. getSize B. setCust C. notAvailable D. isReadable 5. Read the following class ClassA, which statement is correct after executing “new ClassA().getValue();”
public class ClassA { public int getValue() { int value = 0; boolean setting = true; String title = "Hello"; if (value || (setting && title == "Hello")) { return 1; } if (value == 1 & title.equals("Hello")) { return 2; } } } A. There is compilation error for ClassA B. It outputs 2 C. It outputs 1 D. Executes OK, but no output

1

6. Given:
public void testIfA() { if (testIfB("true")) { System.out.println("True"); } else { System.out.println("Not true"); } } public Boolean testIfB(String str) { return Boolean.valueOf(str); } What is the result when method testIfA is invoked? A. True B. Not true

C. An exception is thrown at runtime 7. Given:

D. Compilation fails

public class Pass { public static void main(String[] args) { int x = 5; Pass p = new Pass(); p.doStuff(x); System.out.print(" main x = " + x); } void doStuff(int x) { System.out.print("doStuff x = " + x++); } }

What is the result? A. doStuff x = 6 main x = 6 C. doStuff x = 5 main x = 6 8. Given:
String a = "str"; String b = new String("str"); String c = "str"; System.out.print(a == b); System.out.print(a == c);

B. doStuff x = 5 main x = 5 D. doStuff x = 6 main x = 5

What is the result? A. truefalse C. falsetrue 9. Given:
33. 34. 35. 36. 37. 38. 39. 40. 41.

B. truetrue D. falsefalse

try { // smoe code here } catch (NullPointerException el) { System.out.print("a"); } catch (RuntimeException el) { System.out.print("b"); } finally { System.out.print("c"); } What is the result if NullPointerException occurs on line 34? A. ac B. abc C. c D. No output

10.Which of the following statements is correct about Java package? A. If there is no package statement used, the current class will not be in any package. B. Package is a way to manage source code, each package contains several “.java” files. C. Using one “import” statement can include the classes from one or more packages. D. A package can contain sub-packages.

2

11.Given:
1. public class Target { 2. private int i = 0; 3. public int addOne() { 4. return ++i; 5. } 6. }

And:
1. public class Client { 2. public static void main(String[] args) { 3. System.out.println(new Target().addOne()); 4. } 5. } Which change can you make to Target without affecting Client? A. Line 4 of class Target can be changed to return i++; B. Line 2 of class Target can be changed to private int i = 1; C. Line 3 of class Target can be changed to private int addOne() { D. Line 2 of class Target can be changed to private Integer i = 0;




12.Given:
public abstract class Shape { int x; int y; public abstract void draw(); public void setAnchor(int x, int y){ this.x = x; this.y = y; } } And a class Circle that extends and fully implements the Shape class. Which is correct? A. Shape s = new Shape(); s.setAnchor(10, 10); s.draw(); B. Circle c = new Shape(); c.setAncohor(10, 10); c.draw(); C. Shape s = new Circle(); s.setAnchor(10, 10); s.draw(); D. Shape s = new Circle(); s.Shape.setAnchor(10, 10); s.shape.draw();

线

13.In Java event handling model, which object responses to and handles events? A. event source object B. listener object C. event object D. GUI component object 14.Given:
public static void main(String[] args) { System.out.print(method2(1, method2(2, 3, 4))); } public int method2(int x1, int x2) { return x1 + x2; } public float method2(int x1, int x2, int x3) { return x1 + x2 + x3; }

What is the result? A. Compilation fails C. 10

B. 0 D. 9

3

15.Given:
public class Test { public Test() { System.out.print("test "); } public Test(String val) { this(); System.out.print("test with " + val); } public static void main(String[] args) { Test test = new Test("wow"); } }

What is the result? A. test C. test with wow 16.Given:

B. test test with wow D. Compilation fails

public class ItemTest { private final int id; public ItemTest(int id) { this.id = id; } public void updateId(int newId) { id = newId; } public static void main(String[] args) { ItemTest fa = new ItemTest(42); fa.updateId(69); System.out.println(fa.id); } }

What is the result? A. Compilation fails B. An exception is thrown at runtime C. A new Item object is created with the preferred value in the id attribute D. The attribute id in the Item object remains unchanged 17.Method m() is defined as below in a parent class, which method in the sub-classes overrides the method m()?
protected double m() { return 1.23; } A. protect int m() { return 1; } B. public double m() { return 1.23; } C. protected double m(double d) { return 1.23; } D. private double m() { return 1.23; }

18.Given:
1. public class abc { 2. int abc = 1; 3. void abc(int abc) { 4. System.out.print(abc); 5. } 6. public static void main(String[] args) { 7. new abc().abc(new abc().abc); 8. } 9. }

Which option is correct? A. Compilation fails only at line 2, 3 C. Compilation fails at line 1, 2, 3, 4 19.Which declaration is correct? A. abstract final class Hl { } B. abstract private move() { } C. protected private number; D. public abstract class Car { }

B. Compilation fails only at line 7 D. The program runs and outputs 1

4

20.Given:
public class Hello { String title; int value; public Hello() { title += "World"; } public Hello(int value) { this.value = value; title = "Hello"; Hello(); } }



And:
Hello c = new Hello(5); System.out.println(c.title);



What is the result? A. Hello C. Hello World 21.Given:
public abstract interface Frobnicate { public void twiddle(String s); }

B. An exception is thrown at runtime D. Compilation fails

线

Which is a correct class? A. public abstract class Frob implements Frobnicate {
public abstract void twiddle(String s) { } } B. public abstract class Frob implements Frobnicate { } C. public class Frob extends Frobnicate { public void twiddle(Integer i) { } } D. public class Frob implements Frobnicate { public void twiddle(Integer i) { } }

22.Which statement is true about has-a and is-a relationships? A. Inheritance represents an is-a relationship. B. Inheritance represents a has-a relationship. C. Interfaces must be use when creating a has-a relationship. D. Instance variables must be used when creating an is-a relationship. 23.Which option has syntax error?
class Animal { … } class Dog extends Animal { … } class Cat extends Animal { … } A. Animal animal = new Dog(); C. Dog dog = (Dog) new Cat();

B. Cat cat = (Cat) new Animal(); D. Cat cat = new Cat();

24.Assume that class A is a sub-class of class B, which of the following figures illustrates their relationship? A. B. C. D.

5

25.Given:
public class Plant { private String name; public Plant(String name) { this.name = name } public String getName() { return name; } } public class Tree extends Plant { public void growFruit() {} public void dropLeaves() {} }

Which statement is true? A. The code will compile without changes. B. The code will compile if the following code is added to the Plant class:
public Plant() { this("fern"); }

C. The code will compile if the following code is added to the Plant class
public Plant(){Plant("fern");}

D. The code will compile if the following code is added to the Tree class:
public Tree() { Plant(); }

26.Which of the following statement is correct about exception handling? A. Exception is an error occurred in runtime, so it should be avoided by debugging. B. Exception is described by the form of objects, their classes are organized by a single-root inheritance hierarchy (级联结构). C. There is no exception any more after executing a try-catch-finally structure. D. In Java, all exceptions should be caught and handled in runtime. 27.What are the two major parts of an object? A. property and behavior B. identity and content C. inheritance and polymorphism D. message and encapsulation 28.Which is the correct output according to the program given bellow?
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 two B. th one that two C. thone that two D. this is one that is two

29.Which fragment can not correctly create and initialize an int array? A. int[] a = {1, 2}; B. int[] a; a = new int[2]; a[0] = 1; a[1] = 2; C. int[] a = new int[2]{1, 2}; D. int[] a = new int[]{1, 2}; 30.What is the output of the following program?
String s1 = "Java"; String s2 = new String("Java"); System.out.println((s1 == s2) + "," + (s1.equals(s2))); A. true,true B. true,false C. false,true D. false,false

6

得分
II.Write the output of the given code. (12 points) 1. (6 points)
public class Bootchy { int bootch; String snootch; public Bootchy() { this("snootchy"); System.out.print("first "); } public Bootchy(String snootch) { this(420, "snootchy"); System.out.print("second "); }





public Bootchy(int bootch, String snootch) { this.bootch = bootch; this.snootch = snootch; System.out.print("third "); } public static void main(String[] args) { Bootchy b = new Bootchy(); System.out.print(b.snootch + " " + b.bootch); } }

线

2. (6 points)
public class TestJava { class A { public A(int v1, int v2) { this.v1 = v1; this.v2 = v2; } int v1; int v2; } void m1(A a1, A a2) { A t; t = a1; a1 = a2; a2=t; } void m2(A a1, A a2) { A t = new A(a1.v1, a1.v2); a1 = new A(a2.v1, a2.v2); a2 = new A(t.v1, t.v2); } void m3(A a1, A a2) { A t = a1; a1.v1 = a2.v1; a1.v2 = a2.v2; a2.v1 = t.v1; a2.v2 = t.v2; } public static void main(String[] args) { TestJava tj = new TestJava(); A a1 = tj.new A(0, 2); A a2 = tj.new A(1, 3); tj.m1(a1, a2); System.out.println(a1.v1+ " " + a2.v2 + " "); tj.m2(a1, a2); System.out.println(a1.v1+ " " + a2.v2 + " "); tj.m3(a1, a2); System.out.println(a1.v1+ " " + a2.v2 + " "); } }

7

得分
III.(16 points) Given:
interface Repeater { /** * Repeat the char `c' n times to construct a String. * @param c the character to be repeated * @param n the times of repeat * @return a string containing all the `c' */ String repeat(char c, int n); } public static void main(String[] args) { Repeater arrayRepeater = new ArrayRepeater(); //(1) Repeater stringRepeater = new StringRepeater(); //(2) Repeater stringBufferRepeater = //(3) Repeater r = //(4) long startTime = System.nanoTime(); for (int i = 0; i < 1000; i++) { r.repeat('s', 10000); } long endTime = System.nanoTime(); long duration = endTime - startTime; System.out.println(duration); } 1. Complete the definition of class ArrayRepeater which appears at //(1) to implement the Repeater by constructing the string using new String(char[]). 2. Complete the definition of class StringRepeater which appears at //(2) to implement the Repeater using string concatenation (use + to join strings). 3. Complete the definition of strigBufferRepeater at //(3) by defining an anonymous class implementing Repeater (i.e. new Repeater(){ ... }), using StringBuffer to construct

the required string. 4. The code below //(4) is designed to test the performance of Repeater r. By assigning different implementation of Repeater to r, the code can output the consumed time (duration). Answer the question: arrayRepeater, stringRepeater, stringBufferRepeater, which consumes the longest time?

得分
IV.Given the code bellow, write the necessary classes to meet the following requirements using the knowledge of interface and polymorphism. (12 points)
public class Test { public static void main(String[] args) { Object[] shapes = { new Circle(5.0), //(3) new Rectangle(5.0, 4.5), //(4) new Circle(3.5) }; //(5) System.out.println("Total Area: " + sumArea(shapes)); } public static double sumArea(Object[] shapes) { double sum = 0; for(int i = 0; i < shapes.length; i++) { if (shapes[i] instanceof CalcArea) { //(1) sum += ((CalcArea) shapes[i]).getArea(); //(2) } } return sum; } } The interface CalcArea in comment //(1) and //(2) is undefined; the class Circle and Rectangle in comment //(3), //(4) and //(5) are undefined either. Please define: 1. interface CalcArea 2. class Circle 3. class Rectangle 8


相关文章:
A卷答案
免费 08年a卷答案 暂无评价 2页 免费 文学史A卷的答案 2页 1财富值如要投诉违规内容,请到百度文库投诉中心;如要提出功能问题或意见建议,请点击此处进行反馈。 ...
A卷答案
2001级A卷答案 暂无评价 3页 5财富值 A卷答案1 暂无评价 2页 1财富值 2008年A卷答案 暂无评价 2页 免费 08年a卷答案 暂无评价 2页 免费 文学史A卷的答...
A卷
( A 卷)一、 单项选择题 (在每小题的四个备选答案中, 选出一个正确的答案, 并将其代码填入题干后的括号内。 每小题 1 分,共 15 分) 1. PCM 高次...
A卷
A卷_司法考试_资格考试/认证_教育专区。A卷(一)单选 1.马克思主义定义: 马克从阶级属性来说, 马克思主义是无产阶级争取自身解放和整个人类 解放的科学理论,是关...
A卷及答案
东莞理工学院成人高等学历教育 大学英语(专科)模拟试题( 卷一) 大学英语(专科)模拟试题(A 卷一)(07 卷) College English Test 请考生注意:此卷为客观题,请在...
综合基础知识A卷考前热身卷
综合基础知识 A 卷考前热身卷客观题部分 一、公共基础知识(每题 0.8 分,共 25 题,共 20 分) 1 下列能够反映“事物在一定条件下是相互转化的”哲学关系原理...
A卷答案
免费 08年a卷答案 暂无评价 2页 免费 文学史A卷的答案 2页 1财富值如要投诉违规内容,请到百度文库投诉中心;如要提出功能问题或意见建议,请点击此处进行反馈。 ...
2013年重庆市中考数学试题和答案(A卷)Word版
重庆市 2013 年初中毕业暨高中招生考试【机密】2013 年 6 月 17 日前 数 学试题(A 卷)班级: 姓名: 考号: (全卷共五个大题,满分 150 分,考试时间 120 ...
A卷
A卷_公务员考试_资格考试/认证_教育专区。A 一、填空题 1、水质污染可以分为化学性污染、物理性污染和生物性污染三种污染类型。 2、测量水的 pH 值时,应适当...
综合检测(A卷)
综合检测(A卷)_高三政史地_政史地_高中教育_教育专区 暂无评价|0人阅读|0次下载|举报文档综合检测(A卷)_高三政史地_政史地_高中教育_教育专区。综合检测(A...
更多相关标签:
抽象 a卷 | 阿卷1128 | a卷和b卷的区别 | 阿卷 | a卷斗鱼 | 抽象tv | 啊卷 | 公务员a卷和b卷的区别 |