面向对象程序设计 2011学年第1学期.doc
文本预览下载声明
华南农业大学期末考试试卷(A卷)
2011学年第1学期 考试科目: 面向对象程序设计
考试类型:闭卷考试 考试时间: 120 分钟
学号 姓名 年级专业
题号 一 二 三 总分 得分 评阅人
试卷说明:
1. 所有答案必须写在答卷上,否则不得分,试卷和答卷均填写学号和姓名。
2. 考试结束时,只上交答卷,试卷自行带走。
3. 常用单词:Serializable、Cloneable、Stream、implements、extends
得分
一、程序填空(20分)
说明:按照每小题的要求填充程序中的空白,使程序能够正确运行,每空2分。
1. 具体类Reader实现了Readable接口。
//Readable.java
public interface Readable { void read(); }
//Reader.java
public class Reader implements Readable {
__ _(1)________ read() { System.out.println(I Can read it.); }
} 2. 在空白处定义一个私有的整型变量m, 使得在方法fun中可以使用该变量
public class Main {
(2)
public static void fun(){
m=m+1;
System.out.println(m);
}
} 3. 填写恰当的修饰符,使任何子类可以继承但无法覆盖类Parent中的method方法。
public class Parent{
(3) void method() { System.out.println(Parent); }
}
4. 以下程序功能为利用二维数组生成并输出下三角矩阵。
import java.util.Scanner;
public class Output {
public static void main(String[] args) {
int array[][];
int rows;
Scanner input = new Scanner(System.in);
System.out.print(输入下三角矩阵的行数:);
rows = input.nextInt();
array = (4) ;
for (int i = 0; i array.length; i++) {
array[i] = (5) ;
for (int j = 0; j array[i].length; j++) {
array[i][j] = j + 1;
}
}
for (int i = 0; i array.length; i++) {
for (int j = 0; j array[i].length; j++) {
System.out.print(array[i][j] + );
}
System.out.println();
}
}
} 5. 以下程序定义了Rectangle和Cuboid两个类。
//类1,Rectangle.java
public class Rectangle {
private int width;
private int length;
public Rectangle() {
(6) //填写语句调用本类另一构造方法将2个数据设为0
}
public Rectangle(int width, int length) {
this.width = width;
this.length = length;
}
public int getArea() { return this.width * this.length; }
public int getWidth() { return width; }
显示全部