java语言程序设计试题_《JAVA语言程序设计》期末考试试题及答案

41528d3028836879cd698677c3999917.gif《JAVA语言程序设计》期末考试试题及答案

《JAVA语言程序设计》期末考试试题及答案(应考必备题库) 一、单选择题 1、编译Java Application 源程序文件将产生相应的字节码文件,这些字节码文件的扩展名为( )。 A. java B. .class C. html D. . 2、设 x = 1 , y = 2 , z = 3,则表达式 y+=z--/++x 的值是( )。 A. 3 B. 3. 5 C. 4 D. 5 3、不允许作为类及类成员的访问控制符的是( )。 A. public B. private C. static D. protected 4、为AB类的一个无形式参数无返回值的方法书写方法头,使得使用类名AB作为前缀就可以调用它,该方法头的形式为( )。 A. static void ( ) B. public void ( ) C. final void ( ) D. abstract void ( ) 二、填空题 1、开发与运行Java程序需要经过的三个主要步骤为 编辑源程序 、 编译生成字节码 和 解释运行字节码 。 2、在Java的基本数据类型中,char型采用Unicode编码方案,每个Unicode码占 用 2 字节内存空间,这样,无论是中文字符还是英文字符,都是占 用 2 字节内存空间。 3、设 x = 2 ,则表达式 ( x + + )/3 的值是 0 。 4、若x = 5,y = 10,则x = y的逻辑值分别为 true 和 false 。 5、 抽象(abstract) 方法是一种仅有方法头,没有具体方法体和操作实现的方法,该方法必须在抽象类之中定义。 最终(final) 方法是不能被当前类的子类重新定义的方法。 6、创建一个名为 MyPackage 的包的语句是package MyPackage ; , 该语句应该放在程序的位置为: 应该在程序第一句 。 7、设有数组定义:int MyIntArray[ ] = { 10 , 20 , 30 , 40 , 50 , 60 , 70}; 则执行以下几个语句后的输出结果是 120 。 int s = 0 ; for (int i = 0 ; i z else System.out.println(“不是三角形“); 12、下面程序段的执行结果是(6 5 4 3 2) int a[] = { 2, 3, 4, 5, 6 }; for (int i = a.length - 1; i >= 0; i--) System.out.print(a[i] + ““); 三、程序阅读题 1、以下程序的输出结果为_ Peter is 17 years old!___。 public class Person { String name; int age; public Person(String name, int age) { this.name = name; this.age = age; } public static void main(String[] args) { Person c = new Person(“Peter“, 17); System.out.println(c.name + “ is “ + c.age + “ years old!“); } } 2、以下程序的输出结果为__课程号:101 课程名:ASP 学分:3___。 public class Course { private String cNumber; private String cName; private int cUnit; public Course(String number, String name, int unit) { cNumber = number; cName = name; cUnit = unit; } public void printCourseInfo() { System.out.println(“课程号:“ + cNumber + “ 课程名:“ + cName + “ 学分:“ + cUnit); } } class CourseTest { public static void main(String[] args) { Course c; c = new Course(“101“, “ASP“, 3); c.printCourseInfo(); } } 3、以下程序的输出结果为__汤姆猫体重:20.0斤___。 public class Tom { private float weight; private static String name; public void setWeight(float weight) { this.weight = weight; } private void out() { System.out.println(name + “体重:“ + weight + “斤“); } public static void main(String[] args) { Tom.name = “汤姆猫“; Tom cat = new Tom(); cat.setWeight(20); cat.out(); } } 4、以下程序的输出结果_姓名:Tom 年龄:15 家庭住址:金水区 电话:66123456 学校:九中_。 public class Father { String name, address, tel; int age; public Father(String name, int age) { this.name = name; this.age = age; } void out() { System.out.print(“姓名:“ + name); System.out.print(“ 年龄:“ + age); } void outOther() { System.out.print(“ 家庭住址:“ + address); System.out.print(“ 电话:“ + tel); } } class Son extends Father { String school; public Son(String name, int age) { super(name, age); } void out() { super.out(); super.outOther(); System.out.println(“ 学校:“ + school); } public static void main(String args[]) { Son son = new Son(“Tom“, 15); son.address = “金水区“; son.school = “九中“; son.tel = “66123456“; son.out(); } } 5、下列程序的运行结果是__12345____。 public class MyClass { int a[] = { 1, 2, 3, 4, 5 }; void out() { for (int j = 0; j 0) y=1; else y=0; else y=-1; System.out.println(y); } } 答案:1 3、 读程序,写出正确的运行结果。 public class Father{ int a=100; public void miner(){ a--; } public static void main(String[] args){ Father x = new Father(); Son y = new Son(); System.out.println(y.a); System.out.println( y.getA()); y.miner(); System.out.println(y.a); System.out.println(y.getA()); } } class Son extends Father{ int a = 0; public void plus(){ a++; } public int getA() { return super.a; } } 答案: 0 100 0 99 三 . 简答题 1. Java语言的特点。 答: 简单性:Java风格类似于C++,但它摒弃了C++中容易引起程序错误的地方 面向对象:Java语言的设计是完全面向对象 分布式: 解释执行: 健壮性:Java提供自动垃圾回收机制,异常处理机制,进行严格的类型检查 平台无关性: 安全性 多线程 动态性 2. 请描述 AWT事件模型。 答: 结合AWT事件模型并举例来说: import java.awt.event.*; 1. 监听对象必须实现对应事件监听器的接口 class MyFirstFrame extends Frame implements ActionListener {.} 2.明确事件监听器的接口形式 public void actionPered ( ActionEvent event) {…} 3. MyFirstFrame 类必须实现接口ActionListener中的所有方法。 4. 注册监听对象. 为了把MyFirstFrame对象注册为两个按钮的事件监听对象,必须在MyFirstFrame 的构造函数中添加语句如下: cancelButton.addActionListener(this); okButton.addActionListener(this); 3. 在 Java中,怎样创建一个线程? 答: 1、定义类来实现Runnable接口 class TestThread implements Runnable { public void run() { …} } 2、继承Thread类来实现 class TestThread extends Thread { TestThread(String name) { super(name); start(); } public void run() {…} }

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值