1、济南铁道职业技术学院考试试题 班级 姓名 学号 2009~2010学年第二学期期末考试 《JAVA语言程序设计》试题 A卷 题号 一 二 三 总 分 得分 注意:1、请勿用铅笔及红笔答卷,否则试卷无效。题中需要写分号的,勿忘书写,否则扣分。 2、答题前将班级,姓名等信息写在密封线里,考试结束检查是否填写有误。 得 分 阅 卷 一、选择题(10个空) 1、在子类中访问父类成员(类的继承应用举例) public class Person
2、1 { private String name; protected int age; public void setName(String na) { name=na; } public void setAge(int ag) { age=ag; } public String getName() { ____________; } public int getAge() { return age; } public void print_p() { System.out.pri
3、ntln("Name:"+name+" Age:"+age); } } public class Teacher1 extends Person1 { Protected String department; public Teacher(String na, int ag, String de) { setName(na); setAge(ag); ____________; } public void print_s() { __________; System.out.println("Department:"+dep
4、artment); } public static void main(String arg[]) { ____________________________; t=new Teacher1("Wang",40,"Computer Science"); t.print_s(); t.setName("Wang Gang"); t.age=50; t.print_s(); } } 2、方法覆盖应用举例 public class CCircle { protected double radius; pu
5、blic CCircle(double r) { radius=r; } public void show() { System.out.println("Radius="+radius);} } public class CCoin extends CCircle { private int value; public CCoin(double r, int v) { ____________ ____________ } 班级 姓名 学号 pu
6、blic void show() { System.out.println("Radius="+radius+" Value="+value); } public static void main(String args[]) { ______________________; CCoin coin=new CCoin(3.0,5); circle.show(); coin.show(); } } 3、final成员方法应用举例—覆盖final方法。 出于安全性考虑,有些方法不允许被覆盖,称为final方法。将方法声明为f
7、inal方法,可以确保调用的是正确的、原始的方法,而不是在子类中重新定义的方法。 public class Mother { int x=100,y=20; public final void sum() { ________; s=x+y; System.out.println("s="+s); } } public class Children extends Mother { int m=20,n=30; public void sum() { int f; _________; System
8、.out.println("f="+f); } public static void main(String args[]) { Children aa=new Children();______________; } } 得 分 阅 卷 二、程序改错题 4、实现接口并继承类应用举例 public interface Automobile { int i = 5; // public、static和final可以省略 void accelent()
9、 // public和abstract可以省略 void maintain(); String forward(); String reverse(); } public class Little_car implements Automobile { public void accelent() { System.out.println("Little_car.accelent()"); } public void maintain() { } public String forward() { } public
10、 String reverse() { return "Little_car reverse"; } } public class Big_car extends Automobile { public void accelent() { System.out.println("Big_car.accelent()"); } public void maintain() { } public String forward(){ return "Big_car forward"; } public String reverse() {
11、} } 班级 姓名 学号 public class Jeep implements Automobile { public void accelent() { System.out.println("Jeep.accelent()"); } public void maintain() { } public String forward(){ } public String reverse() { return "Jeep reverse";
12、 } } public class Microbus extends Big_car { public void accelent() { System.out.println("Microbus.accelent()"); } public void maintain() { System.out.println("Microbus.maintain()"); } } public class Bus extends Big_car { public String forward(){ return "Bus forward";}
13、 public String reverse() { return "Bus reverse";} } public class Car { public static void main(String args[]) { Automobile[] cars=new Automobile[5]; int i = 0; cars[i--]=new Little_car(); cars[i++]=new Big_car(); cars[i++]=new
14、Jeep();
cars[i++]=new Microbus();
cars[i++]=new Bus();
for( i=0;i 15、 Exception1
{
public static void main(String args[])
{
try
{
int a[] = { 1, 2, 3, 4, 5 },
for (int i = 0; i <= 5; i++) sum = sum - a[i];
System.out.println("sum=" + sum);
System.out.println("Successfully!");
}
catch (ArrayIndexOutOfBoundsException e)
{
System.out.pri 16、ntln("ArrayIndexOutOfBoundsException detected");
}
finally
{
System.out.println(" Programm Finished!");
}
}
}
班级 姓名 学号
6、Java实例—以字节流方式读磁盘文件
import java.io.*;
public class File 3
{
public static void main(String args[]) throws IOExcept 17、ion
{
int ch;
File file1 = new File("c:\\jdk1.3\\example\\newFile.txt");
try
{
FileInputStream fin = new FileInputStream(file1);
System.out.println("文件中的信息为:");
ch = fin.read();
while (ch = -1)
{
System.out.print((char) ch);
ch = fin.read();
}
18、
}
catch (FileNotFoundException e)
{
System.out.println(e);
}
catch ()
{
System.out.println(e);
}
}
}
得 分
阅 卷
三、Java编程题(本大题共2个小题)
1、用FOR语句编程输出如下图形。(20分)
*
**
***
****
*****
2、用for语句,计算1+2+3+…+100的和。(20分)
《 JAVA语言程序设计 》期末试题 第 9 页,共 8 页 《 JAVA语言程序设计 》期末试题 第 10 页,共 8 页






