JAVA全英试卷.doc_第1页
JAVA全英试卷.doc_第2页
JAVA全英试卷.doc_第3页
JAVA全英试卷.doc_第4页
JAVA全英试卷.doc_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

装订线华南农业大学期末考试试卷(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 .exeB.jar and .classC.java and .classD.jar and .exe3 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 CertKiller4 Which method name does not follow the JavaBeans standard on Accessor/Mutator? A.getSizeB.setCustC.notAvailableD.isReadable5 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 ClassAB.It outputs 2C.It outputs 1D.Executes OK, but no output6 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.TrueB.Not trueC.An exception is thrown at runtimeD.Compilation fails7 Given: 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 = 6B.doStuff x = 5 main x = 5C.doStuff x = 5 main x = 6D.doStuff x = 6 main x = 58 Given: String a = str;String b = new String(str);String c = str;System.out.print(a = b);System.out.print(a = c);What is the result?A.truefalseB.truetrueC.falsetrueD.falsefalse9 Given: 33. try 34. / smoe code here35. catch (NullPointerException el) 36. System.out.print(a);37. catch (RuntimeException el) 38. System.out.print(b);39. finally 40. System.out.print(c);41. What is the result if NullPointerException occurs on line 34?A.acB.abcC.cD.No output10 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.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 objectB.listener objectC.event objectD.GUI component object14 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 failsB.0C.10D.915 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.testB.test test with wowC.test with wowD.Compilation fails16 Given: 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 failsB.An exception is thrown at runtimeC.A new Item object is created with the preferred value in the id attributeD.The attribute id in the Item object remains unchanged17 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, 3B.Compilation fails only at line 7C.Compilation fails at line 1, 2, 3, 4D.The program runs and outputs 119 Which declaration is correct? A.abstract final class Hl B.abstract private move() C.protected private number;D.public abstract class Car 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.HelloB.An exception is thrown at runtimeC.Hello WorldD.Compilation fails21 Given: public abstract interface Frobnicate public void twiddle(String s);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();B.Cat cat = (Cat) new Animal();C.Dog dog = (Dog) new Cat();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.25 Given: public class Plant private String name; public Plant(String 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 classpublic 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 behaviorB.identity and contentC.inheritance and polymorphismD.message and encapsulation28 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 twoB.th one that twoC.thone that twoD.this is one that is two29 Which fragment can not correctly create and initialize an int array? A.int a = 1, 2;B.int a; a = new int2; a0 = 1; a1 = 2;C.int a = new int21, 2;D.int a = new int1, 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,trueB.true,falseC.false,trueD.false,false得分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); third second first snootchy4202 (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 + ); 0 3 0 3 1 3得分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?-(1)class ArrayRepeater implements Repeaterpublic String repeat(char c ,int n)char arr = new charn;for(int i=0;in;i+)arri=c;String s = new String(arr);return s;(2) class StringRepeater implements Repeater public String repeat(char c,int n)String s =;for(int i=0;in;i+)s=s+c;return s;(3) ne

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论