java面向对象程序设计期末测试题

测试题一

1.The term wrapper classes refers to

 

A.

the Java classes that contain at least two data fields

 

B.

a collection of Java classes that contain other Java classes

 

C.

the Java classes that contain themselves

 

D.

a collection of Java classes that "wrap" Java primitive types

所选答案: B. 

a collection of Java classes that contain other Java classes

正确答案: D. 

a collection of Java classes that "wrap" Java primitive types

 

 

2.Given the following code, what value will be output by the last statement?

StringTokenizer st = new StringTokenizer("this is,a,test of tokens", ",");

  String s; 

 int count = 0;    

while (st.hasMoreTokens())  

{        s = st.nextToken();  

      ++count; 

 } 

 stdOut.println(count);

 

A.

4

 

B.

1

 

C.

3

 

D.

6

所选答案:

 A. 

4

正确答案:

 C. 

3

 

 

3.Which of the following statements is (are) true about the use of an asterisk (*) in a Java import statement?

1. It does not incur run-time overhead.

2. It can be used to import multiple packages with a single statement.

3. It can be used to import multiple classes with a single statement.

 

A.

3 only

 

B.

1, 2, and 3

 

C.

1 and 3 only

 

D.

1 only

所选答案: A. 

3 only

正确答案: C. 

1 and 3 only

 

 

4.Consider the following Java program segment.

   int x = 5;     int y = 2;     System.out.println(x + "1" + y);

Which of the following statements is true about the program segment?

 

A.

The code will cause a compilation error.

 

B.

The output caused by the code will be 512.

 

C.

 The output caused by the code will be 5 1 2.

 

D.

The output caused by the code will be 8.

所选答案: B. 

The output caused by the code will be 512.

正确答案: B. 

The output caused by the code will be 512.

 

 

5.Which of the following patterns of characters opens a Javadoc comment block?

 

A.

//

 

B.

**/

 

C.

/**

 

D.

/*

所选答案: D. 

/*

正确答案: C. 

/**

 

6.Classes from which of the following packages are implicitly imported into every Java program?

 

A.

java.util

 

B.

java.lang

 

C.

java.awt

 

D.

java.io

所选答案: B. 

java.lang

正确答案: B. 

java.lang

 

 

7.The name of a Java source file

 

A.

must be the same as the class it defines, ignoring case

 

B.

 has no restrictions

 

C.

must use the extension .class

 

D.

must be the same as the class it defines, respecting case

所选答案:

 D. 

must be the same as the class it defines, respecting case

正确答案:

 D. 

must be the same as the class it defines, respecting case

 

 

8.What will be output when the following Java program segment is executed?

   int x = 5;     int y = 2;     System.out.println(x + y);

 

A.

5+2

 

B.

7

 

C.

52

 

D.

5 2

所选答案:

 B. 

7

正确答案:

 B. 

7

 

 

9.What is the right way to handle abnormalities in input on Java?

 

A.

By always specifying the throws clause in every method header where file I/O is performed

 

B.

By using the class FileFilter which gracefully filters out bad input data

 

C.

By handling these problems by providing exception handlers

 

D.

By writing while loops to guard against bad input

所选答案:

 A. 

By always specifying the throws clause in every method header where file I/O is performed

正确答案:

 C. 

By handling these problems by providing exception handlers

 

 

10.A tool that allows programmers to execute lines of a program one line at a time in order to help locate the source of a program's errors is known as a(n)

 

A.

exception handler

 

B.

stack trace

 

C.

scope

 

D.

debugger

所选答案:

<
  • 5
    点赞
  • 41
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java面向对象程序设计期末考试试题及答案 1. 请简要说明面向对象程序设计的三大特征。 答案:封装、继承和多态是面向对象程序设计的三大特征。封装指的是将数据和操作数据的方法封装在一起,可以通过访问权限控制提高安全性;继承指的是子类可以继承父类的属性和方法,便于代码重用;多态指的是同一个方法名可以有多种不同的实现方式,实现了代码的灵活性和扩展性。 2. 请使用Java语言编写一个简单的类,并在主函数中实例化这个类。 答案:代码如下 ```java public class Person { private String name; private int age; public Person(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public int getAge() { return age; } public static void main(String[] args) { Person person = new Person("Tom", 25); System.out.println("Name: " + person.getName()); System.out.println("Age: " + person.getAge()); } } ``` 3. 请简要说明抽象类和接口的区别。 答案:抽象类是一种包含抽象方法的类,不能被实例化,只能被继承;接口是一种只包含抽象方法和常量的类,实现接口的类必须实现接口中定义的所有方法。一个类可以实现多个接口,但只能继承一个抽象类。 4. 请使用多态的概念简要说明方法重写和方法重载的区别。 答案:方法重写是子类重新定义了父类的方法,实现了多态,调用父类引用指向子类对象时将调用子类的方法;方法重载是在一个类中可以定义多个方法名相同但参数列表不同的方法,通过参数的类型、个数和顺序来区分调用不同的方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值