学期:2020年秋季

课程名称【编号】:面向对象程序设计【0837】 A卷

考试类别:大作业 满分:100分

一、单项选择题(共10小题,3分/题,共30分)

1. Java语言具有许多优点和特点,下列选项中,哪个反映了Java程序“一次编写,到处运行”的特点:( )

A. 多线程

B. 与平台无关

C. 面向对象

D. 分布式

2. 下列字符序列中可以作为Java语言标识符的是:( )

A. true

B. 123_xyz

C. x.y

D. _x123

3. 下列选项中,用于声明实现一个接口关键字是:( )

A. interface

B. implements

C. import

D. abstract

4. 设有定义 int i=7;char ch='b'; 下面赋值语句中不正确是:( )

A. i = ch;

B. ch = i;

C. ch = (char)i;

D. i = (int)ch;

5. 以下由for 语句构成的循环的执行次数是:( )

for ( int i = 0; i<=0; i = i ) ;

A. 有语法错,不能执行

B. 一次也不执行

C. 执行1次

D. 无限次

6. 既能作为类的修饰符, 也能作为类成员的修饰符的是( )

A. public

B. extends

C. void

D. private

7. 下列构造String的语句中,不正确的是:( )

A. String str2 = “” ;

B. String str1 = new String( );

C. String str4 = “” + 123;

D. String str3 = new String(123);

8. 下列语句序列给出了myArr,k与myMethod()的声明。当调用方法myMethod(myArr,k)之后,存储在myArr和k里的值分别是:( )

String myArr[] = {“peace”,“love”,“and”};

int k = 7;

void myMethod(String a[], int m) {

String temp = a[1];

a[1] = a[2];

a[2] = temp;

m = a[2].length();

}

A. {“peace”,“love”,”and”},7

B. {“peace”,“love”,”and”},4

C. {“peace”,“and”,”love”},7

D. {“peace”,“and”,”love”},4

9. 把容器划分为东、西、南、北、中5个区域的布局管理器是:( )

A. BoxLayout

B. FlowLayout

C. CardLayout

D. BorderLayout

10. 从开始执行到执行结束,小应用程序经历的3个状态分别是:( )

A. 初始态、就绪态,结束态

B. 就绪态、运行态,停止态

C. 初始态、运行态,停止态

D. 就绪态、运行态,休眠态

二、程序分析题(共4小题,每小题各10分,共40分)

1. 阅读下面的程序,写出程序运行的输出结果。

public class Test1 {
public int method(int n) {
int result = 1;
for(int i=1; i<=n; i++) {
result *= i;
}
return result;
}
public static void main( String[] args) {
Test1 test = new Test1( );
int sum[ ] = new int[6];
for ( int i=1; i <=5; i++) {
sum[i] = test.method(i) ;
System.out.print(sum[i] + " ");
}
}
}

2. 阅读下面的程序,写出程序运行的输出结果。

public class Test2 {
public static char method(char ch){
if((ch>='A') && (ch<='Z'))
return (char)(ch + 32);
else return ch;
}
public static void main(String[] args) {
String s= "0123456789ABCDEF",s1="";
for (int i=s.length()-1; i>=0; i--)
s1 = s1 + method(s.charAt(i));
System.out.println(s1);
}
}

3. 阅读下面程序,并回答问题。

class Parent {
public void printMe( ) {
System.out.println("parent");
}
}
class Child extends Parent {
public void printMe( ) {
System.out.println("child");
}
public void printAll( ) {
super.printMe( );
this.printMe( );;
}
}
public class Test3 {
public static void main(String[] args) {
Child myC = new Child( );
myC.printAll( );
}
}

问题(1):类Child和类Parent之间是什么关系?

问题(2):关键字super和this分别是什么含义?

问题(3):这段程序的输出是什么?

4. 阅读下面程序,并回答问题。

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Test4 extends JApplet implements ActionListener{
private Container cp = getContentPane();;
private JLabel prompt = new JLabel("请点击按钮");
private JButton start = new JButton("开始");
private JTextField output = new JTextField(20);
public void init( ){
cp.setLayout(new FlowLayout());
cp.add(start);
cp.add(prompt);
cp.add(output);
output.setEditable(false);
start.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if ((JButton)e.getSource( ) == start )
output.setText("好好学习,天天向上");
}
}

问题(1):Java程序分为哪两种类型,这段程序是哪一类Java程序?

问题(2):这个图形用户界面上包含那几类组件?点击按钮后程序显示什么?

问题(3):ActionListener是什么?程序中哪个方法是ActionListener中的方法?其功能是什么?

三、程序设计题(共1小题,共30分)

编写一个简单的乘法器,界面如下图所示,在第一个文本框中输入第一个乘数;在第二个文本框中输入第二个乘数;当单击“=”按钮时,在第三个文本框中输出其乘积。