Java语言程序设计单元测试3

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

临沂师范学院2009—2010学年度第1学期

《Java语言程序设计》单元测试3

I Single-choice Topic (30 points)

1. Assume double m =45.5, Which of the following statement output this variable value? ________

A. System.out.printf(“m =%f”,m);

B. System.out.printf(“m =%d”,m);

C. System.out.printf(“m =%s”,”m”);

D. System.out.printf(“m =%s”,m);

2. Which of the following initializer lists would correctly set the elements of array n?

A. int[] n = { 1, 2, 3, 4, 5 ,6,7,8 };.

B. array n[ int ] = { 1, 2, 3, 4, 5 ,6,7,8 };.

C. int n[ 5 ] = { 1; 2; 3; 4; 5 ;6;7;8 };.

D. int n = new int( 1, 2, 3, 4, 5 ,6,7,8);.

3. Which of the following elements should usually be private?________ A.methods B.constructors C.variables (or fields). D.All of the above

4. Analyze the following code and select the correct choice __________

public class Test {

public static void main(String[] args) { add(23, 67); }

public static void add(int n, int f) {System.out.println("return void”);}

public static int add(int x, int y) { System.out.println("return int");

return x; }}

A. The program displays return void.

B. The program displays long, long.

C. The program display an exception.

D. The program does not compile because the compiler cannot distinguish which info method to call.

5 What is k after the following block executed? __________

{ int i = 2; System.out.println("A message" + i );}

A. 1

B. 2

C. 3

D. k is not defined outside the block.

6. The visibility of these modifiers increases in this order:__________.

A. private, protected, none (if no modifier is used), and public.

B. private, none (if no modifier is used), protected, and public.

C. none (if no modifier is used), private, protected, and public.

D. none (if no modifier is used), protected, private, and public.

7.What is the output of running A? ___________

public class A extends B {

int x = 1;

public static void main(String[] args) {

System.out.print(new A().x);

System.out.print(new B().x); }}

class B { int x = 5; }

A. 1 5

B. 5 1

C. 1 1

D. 5 5

8. What modifier should you use on a class so that a class in the same package can access it but a class in a different package cannot access it______?

A. public

B. private

C. protected

D. Use the default modifier.

9. Which of the following classes cannot be extended_________?

class My { } B. abstract class My{ private test();}

C. class My {protected A() { };}

D. final class My {}

10. What is the output of the following code: _________

public class Test {

public static void main(String[] args) {

Object o1 = new Object(); Object o2 = new Object();

System.out.print((o1 == o2) + " " + (o1.equals(o2))); }}

A. false false

B. true true

C. false true

D. true false

11.Which of the following classes is an abstract class________?

abstract class A{ } B. public classA{ } C. final class A { } D. static class A { } 12. Which of the following declares an abstract method in an abstract Java class________?

A. public abstract method();

B. public abstract void method();

public void static Method(); D. public void method() {}

13.which of the following keywords is used to define an interface?_____

相关文档
最新文档