收藏 分销(赏)

JAVA语言程序设计(二)期末试题.doc

上传人:仙人****88 文档编号:7596481 上传时间:2025-01-10 格式:DOC 页数:5 大小:78.50KB 下载积分:10 金币
下载 相关 举报
JAVA语言程序设计(二)期末试题.doc_第1页
第1页 / 共5页
JAVA语言程序设计(二)期末试题.doc_第2页
第2页 / 共5页


点击查看更多>>
资源描述
济南铁道职业技术学院考试试题 班级 姓名 学号 2009~2010学年第二学期期末考试 《JAVA语言程序设计》试题 A卷 题号 一 二 三 总 分 得分 注意:1、请勿用铅笔及红笔答卷,否则试卷无效。题中需要写分号的,勿忘书写,否则扣分。 2、答题前将班级,姓名等信息写在密封线里,考试结束检查是否填写有误。 得 分 阅 卷 一、选择题(10个空) 1、在子类中访问父类成员(类的继承应用举例) public class Person1 { 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.println("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:"+department); } 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; public 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) { ____________ ____________ } 班级 姓名 学号 public 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方法。将方法声明为final方法,可以确保调用的是正确的、原始的方法,而不是在子类中重新定义的方法。 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.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(); // 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 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() { } } 班级 姓名 学号 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"; } } 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";} 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 Jeep(); cars[i++]=new Microbus(); cars[i++]=new Bus(); for( i=0;i<cars.length;i++) cars[i].accelent(); } } 程序运行结果如下: Little_car.accelent() Big_car.accelent() Jeep.accelent() Microbus.accelent() Big_car.accelent() 5、捕获数组下标越界异常应用举例 public class 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.println("ArrayIndexOutOfBoundsException detected"); } finally { System.out.println(" Programm Finished!"); } } } 班级 姓名 学号 6、Java实例—以字节流方式读磁盘文件 import java.io.*; public class File 3 { public static void main(String args[]) throws IOException { 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(); } } 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 页
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 教育专区 > 小学其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服