收藏 分销(赏)

面向对象程序设计JAVA语言程序设计期末考试试题及部分答案.doc

上传人:精**** 文档编号:9798051 上传时间:2025-04-08 格式:DOC 页数:18 大小:63.54KB 下载积分:8 金币
下载 相关 举报
面向对象程序设计JAVA语言程序设计期末考试试题及部分答案.doc_第1页
第1页 / 共18页
面向对象程序设计JAVA语言程序设计期末考试试题及部分答案.doc_第2页
第2页 / 共18页


点击查看更多>>
资源描述
一、单选题 1. 在下列概念中,Java语言只保留了D A.运算符重载 B.结构与联合 C.指针 D. 方法重载 2. 下列类定义中,不正确是B A.class x { .... } B.static class x implements y1,y2 { .... } C.public class x extends Applet { .... } D.class x extends y { .... } 3. 下列语句序列执行后,k 值是B int m=3, n=6, k=0; while( (m++) < (- - n) ) ++k; i++ 先把i初值赋给表达式(i++),作为表达式(i++)值,然后i自增1作为i值。 如i=1,则表达式(i++)值等于1,而i值变为2。 ++i i先自增1,再把自增后值赋给表达式(++i)。 如i=1,则表达式(++i)值等于2,i值也为2, A.0 B.1 C.2 D.3 4. 设i、j为int型变量名,a为int型数组名,以下选项中,正确赋值语句是A A.a[0] = 7; B.i = i + 2 C.i++ - --j; D.a(0) = 66; 5. Java语言类间继承关系是B A.多重 B.单重 C.线程 D.不能继承 6. 下列语句序列执行后,k 值是C int i=10, j=18, k=30; switch( j - i ) { case 8 : k++; case 9 : k+=2; case 10: k+=3; default : k/=j; A.31 B.3 C.2 D.33 7. 设有定义 float x=3.5f, y=4.6f, z=5.7f;则以下表达式中,值为true是C A.x > y || x > z B.z > ( y + x ) C.x != y D.x < y & ! ( x < z ) 8. 下列修饰符中,定义类头时能使用修饰符是C A.private B.static C.abstract D.protected 9. 设i、j、k为类x中定义int型变量名,下列类x构造函数中不正确是B A.x( int m){ ... } B.void x( int m){ ... } C.x( int m, int n){ ... } D.x( int h,int m,int n){ ... } 10. 下列对封装性描述中,错误是 D A.封装体包含了属性与行为 B.封装使得抽象数据类型提高了可重用性 C.被封装某些信息在封装体外是不可见 D.封装体中属性与行为访问权限是相同 11. 下列关于包描述中,错误是 B A.包是若干个类集合 B.包是一种特殊类型 C.包是使用package语句创建 D.包有有名包与无名包两种 12. 下列关于Applet程序描述中,错误是 C A.Applet程序主类必须是Applet类得子类 B.Applet不是完整独立程序 C.Applet程序主类中应有一个main()方法 D.Applet字节码文件必须嵌套在一个HTML文件中 13. 下列界面元素中,不是容器是 C A. Dialog B.Frame C.List D.Panel 14. 下列关于异常处理描述中,错误是 D A.程序运行时异常由Java虚拟机自动进行处理 B.使用try-catch-finally语句捕获异常 C.使用throw语句抛出异常 D.捕获到异常只能在当前方法中处理,不能在其他方法中处理 15. 以下方法不属于迭代器(Iterator)接口所定义方法是 D A.hasNext() B.next() C.remove() D.nextElement() 16. 主线程属于 (C ) A.守护线程 B.Thread线程 C.用户线程 D.Runnable线程 二、填空题 1. 三目运算符3个操作数中,第一个操作数类型必须是 逻辑 型。 2. 在Java基本数据类型中,char型采用Unicode编码方案,每个Unicode码占用 2 字节内存空间,这样,无论是中文字符还是英文字符,都是占用 2 字节内存空间。 3. 假设x=13,y=4,则表达式x%y != 0值是 true ,其数据类型是 布尔型 。 4. Java语言中,多态性主要表现在两个方面: 方法重载 与 成员覆盖 。 5. 定义类关键字是 class ,定义接口关键字是 interface 。 6. 在Java语言中,通过类定义只能实现 单 重继承,但通过接口定义可以实现 多 重继承关系。 7. 在Java中字符串包括字符串常量与字符串变量,分别由类 String 与类 StringBuffer 来创建对象。 8. Java 源程序文件编译后产生文件称为 ·class 文件,其扩展名为 ·java 。 9. 在多线程程序设计中,若要启动一个线程需要调用函数是 start 。 10. 在Java语言中,系统规定:表示当前类构造方法用 this ,表示直接父类构造方法用 super 。 17. Java语言规定标识符是由 字母 、 下划线 、 数字 与 美元符号 组成字符序列,长度不限;又规定第一个字符不能是 数字 ,并区分字母大小写。 18. Java中实现多线程一般使用两种方法,一是Thread,二是 Runnable 。 19. Java中变量有三要素: 类型 、 变量名 与 变量值 。 20. Java语言中,说明或声明数组时 内存大小,创建数组时 内存大小。 21. 集合框架提供Map接口实现类中,在Map中插入、删除与定位元素,使用 HasMap 是最好选择;需要按顺序遍历键,需选择 ThereMap 。 22. Outputstream 类与 Inputstream类是所有字节流输入输出类父类。 23. 导入my.package包中所类命令是 import 。 24. 构造方法是一种特殊成员方法,构造方法名与 类 相同,并且此方法 无 有返回值。 25. 图形用户界面设计中有事件处理模型处理事件,在该模型中主要包括 事件源、 事件对象 与 事件监听者 。 三、判断题 1. Java语言具有较好安全性与可移植性及与平台无关等特性。T 2. Java语言基本数据类型有4种:整型、浮点型、字符型与布尔型。T 3. 组成Java Application若干类中,有且仅有一个主类,只有主类中含有主方法main。T 4. 数据由高类型转换到低类型时候,采用强制转换,数据精度要受到损失。T 5. 子类所继承父类成员都可以在子类中访问。 6. 静态方法只能处理静态变量。T 7. 抽象方法是一种只有说明而无具体实现方法。 8. Java语言规定在嵌套程序块中不允许定义同名成员变量。 9. Throwable类有两个子类:Error类与Exception类。前者由系统保留,后者供应用程序使用。 10. 运行Applet程序是使用AppletViewer命令运行嵌入了字节码文件html文件,从而获得运行结果。 11. 成员方法重载与覆盖是同一回事。 12. 集合Set是通过键-值对方式来存储对象。 13. Java语言是一种强类型语言,数据类型转换有两种:隐含转换与强制转换。 14. Java语言中,数组在静态与动态赋值时都判越界。 15. Frame容器是有边框容器,它也是一种独立窗口,只能作为最外层容器。 16. 死锁产生是因为多个线程间存在资源竞争。 1.组成Java Application若干类中,有且仅有一个主类,只有主类中含有主方法main。( ) 2.数据由高类型转换到低类型时候,采用强制转换,数据精度要受到损失。 ( ) 3.成员方法重载与覆盖是同一回事。 ( ) 4.抽象方法是一种只有说明而无具体实现方法。 ( ) 5.Java2事件处理方法是采用委托事件处理模型。 ( ) 6.Throwable类有两个子类:Error类与Exception类。前者由系统保留,后者供应用程序使用。 ( ) 7.运行Applet程序是使用AppletViewer命令运行嵌入了字节码文件html文件,从而获得运行结果。 8.Java语言具有较好安全性与可移植性及与平台无关等特性。 ( ) 9.Java语言基本数据类型有4种:整型、浮点型、字符型与布尔型。 ( ) 10.子类所继承父类成员都可以在子类中访问。 ( ) 11.Java语言规定在嵌套程序块中不允许定义同名成员变量。 ( ) 12.Java语言采用16位颜色标准。Java调色板保证128色。 13.静态方法只能处理静态变量。 ( ) 14.画布(Canvas)是一种可容纳多个组件容器。 ( ) 15.Java语言是一种强类型语言,数据类型转换有两种:隐含转换与强制转换。 ( ) 16.Java语言中,数组在静态与动态赋值时都判越界。 ( ) 17.Frame容器是有边框容器,它也是一种独立窗口,只能作为最外层容器。 ( ) 18.集合Set是通过键-值对方式来存储对象。 19.异常处理是在编译时进行。 ( ) 20.死锁产生是因为多个线程间存在资源竞争。 ( ) 四、阅读下列程序,请写出程序输出结果 class B { int b; B(int x) { b = x; System.out.println("b=" + b); class A extends B { int a; A(int x, int y) { super(x); a = y; System.out.println("b=" + b + ",a=" + a); public class Test { public static void main(String[] args) { A obj = new A(13, 23); 答案 b=13 b=13,a=23 public class Test1 { public static void main(String[] agrs) { AB s = new AB("Hello!", "I love JAVA."); System.out.println(s.toString()); class AB { String s1; String s2; AB(String str1, String str2) { s1 = str1; s2 = str2; public String toString() { return s1 + s2; 答案 Hello!I love JAVA. 3.public class Test { public static void main(String[] args) { int[][] num1 = new int[2][3]; num1[0][0] = 3; num1[0][1] = 9; num1[0][2] = 60; num1[1][0] = 78; num1[1][1] = 79; for (int i = 0; i <= 1; i++) { for (int j = 0; j < num1[i].length; j++) System.out.print(num1[i][j] + "\t"); System.out.println(); 答案 3 9 60 78 79 0 4. public class Test { public static void main(String[] agrs) { int i, s = 0; int a[] = { 10, 20, 30, 40, 50, 60, 70, 80, 90 }; for (i = 0; i < a.length; i++) if (a[i] % 3 == 0) { s += a[i]; System.out.println("s=" + s); 答案 s=30 s=90 s=180 5. public class Test3 { public static void main(String[] agrs) { A a = new A(2); A b = new A(3); System.out.println(a.isEqualTo(b)); class A { private int privateVar; public A(int _privateVar) { privateVar = _privateVar; } boolean isEqualTo(A anotherA) { if (this.privateVar == anotherA.privateVar) return true; else return false; 答案 false 6. public class Test { public static void main(String[] args) { int[][] num1 = new int[2][3]; num1[0][0] = 3; num1[0][1] = 9; num1[0][2] = 45; num1[1][0] = 78; num1[1][1] = 79; for (int i = 0; i <= 1; i++) { for (int j = 0; j < num1[i].length; j++) System.out.print(num1[i][j] + "\t"); System.out.println(); int[][] num2 = new int[][] { { 1, 2, 3 }, { 7, 8 } ,{ 9 } }; for (int i = 0; i <num2.length; i++) { for (int j = 0; j < num2[i].length; j++) System.out.print(num2[i][j] + "\t"); System.out.println(); 答案 3 9 45 78 79 0 1 2 3 7 8 9 7. public class Test2 { public static void main(String[] agrs) { int i, s = 0; int a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; for (i = 0; i < a.length; i++) if (a[i] % 3 == 0) { s += a[i]; System.out.println("s=" + s); 答案 s=3 s=9 s=18 8. class B { int b; B(int x) { b = x; System.out.println("b=" + b); class A extends B { int a; A(int x, int y) { super(x); a = y; System.out.println("b=" + b + ",a=" + a); public class Test { public static void main(String[] args) { A obj = new A(5, 10); 答案 b=5 b=5,a=10 9. public class Test4 { public static void main(String[] agrs) { try { method(); } catch (Exception e) { System.out.println("A"); } finally { System.out.println("B"); static void method() { try { wrench(); System.out.println("C"); } catch (ArithmeticException e) { System.out.println("D"); } finally { System.out.println("E"); System.out.println("F"); static void wrench() { throw new NullPointerException(); 答案 E A B 五、阅读程序,回答问题 1. 1: public class Output1 { 2: public static void main(String arge[]) { 3: int i=0; 4: for ( char ch = 97; ch<113; ch++,i++) { 5: if( i % 8 == 0 ) 6: System.out.println(" "); 7: System.out.print("\t" +ch); 8: } 9: } 10: } (1)程序第5、6行if语句功能是什么? (2)程序输出结果有几行? 2. 1: import java.util.Arrays; 2: public class SortArray { 3: public static void main(String args[]) { 4: String[] str = {"size", "abs","length","class"}; 5: Arrays.sort(str); 6: for (int i=0; i<str.length; i++) 7: System.out.print(str[i]+" "); 8: } 9: } (1)写出程序运行后结果。 (2)在第4行与5行之间,进行str[0].length()方法调用返回结果是多少? 3. abstract class SuperAbstract{ void a(){…} abstract void b(); abstract int c(int i); interface AsSuper{ void x(); abstract class SubAbstract extends SuperAbstract implements AsSuper{ public void b(){…} abstract String f(); public class InheritAbstract extends SubAbstract{ public void x(){…} public int c(int i ) {…} public String f(){…} public static void main(String args[]){ InheritAbstract instance=new InheritAbstract(); instance.x(); instance.a(); instance.b(); instance.c(100); System.out.println(instance.f()); 根据以上这段程序,回答问题: (1)哪几个类是抽象类,写出类名。 (2)哪几个类是非抽象类,写出类名。 (3)是否有接口,写出接口名。 4.定义类A与类B如下。 class A{ int a=1; double d=2.0; void show( ) { System.out.println("Class A: a="+a +"\td="+d); class B extends A{ float a=3.0f; String d="Java program."; void show( ) { super.show( ); System.out.println("Class B: a="+a +"\td="+d); 若在应用程序main方法中有以下语句: A a=new A(); a.show(); 则输出结果如何?Class A: a=1 d=2.0 5.写出此程序完成功能。 public class Sum { public static void main(String args[]) { double sum = 0.0; for (int i = 1; i <= 100; i++) sum += 1.0 / (double) i; System.out.println("sum=" + sum); 回答问题:以上程序完成什么功能? 运行结果是:sum=5.9621 6.写出此程序完成功能。 import java.io.*; public class ArrayCount { public static void main(String[] args) { int i, n = 10, sum = 0, count = 0; int a[] = new int[10]; for (i = 0; i < n; i++) try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); a[i] = Integer.parseInt(br.readLine()); } catch (IOException e) { for (i = 0; i < n; i++) sum += a[i]; sum /= n; for (i = 0; i < n; i++) if (a[i] < sum) ++count; System.out.println(count); 7. import java.util.*; public class Test4{ public static void main(String args[]) { Set set = new TreeSet(); set.add(new Integer(10)); set.add(new Integer(5)); set.add(new Integer(15)); set.add(new Integer(5)); set.add(new Integer(10)); System.out.println("size = " + set.size()); Iterator it = set.iterator(); while (it.hasNext()) { System.out.print(it.next() + " "); (1)程序运行后输出结果如何? size = 3 5 10 15 (2)说明java中集合(Set接口)与映射(Map接口)主要区别。 8. 1: import java.applet.Applet; 2: import java.awt.*; 3: import java.awt.event.*; 4: public class TestKeyListener extends Applet { 5: Color clr; 6: public void init() { 7: addKeyListener( 8: new KeyAdapter() { 9: public void keyTyped( KeyEvent e ) { 10: if(e.getKeyChar()=='r'||e.getKeyChar()=='R') 11: clr=Color.red; 12: else if(e.getKeyChar()=='g'||e.getKeyChar()=='G') 13: clr=Color.green; 14: else if(e.getKeyChar()=='b'||e.getKeyChar()=='B') 15: clr=Color.blue; 16: else 17: clr=Color.black; 18: setBackground(clr); 19: } 20: }); 21: } 22: } (1)程序第10、11行实现功能是什么?返回引发键盘事件按键所对应Unicode字符,如果为大写R或小写r则让变量clr等于Color类red方法。 (2)编译该程序,并编写嵌入该程序字节码文件网页后,通过支持java浏览器打开网页。如果敲击键盘‘b’键,有什么结果? 六、程序设计题 1. 设计一个Calculator类,并完成下列各方法程序设计并测试: (1)定义add()方法,用来计算两数(a,b)之与。 (2)定义sub()方法,用来计算两数(a,b)之差。 (3)定义mul()方法,用来计算两数(a,b)之积。 (4)定义div()方法,用来计算a/b。 public class kk { int a, b; int add() { return (a + b); int sub() { return (a - b); int mul() { return (a * b); int div() { if (b != 0) return (a / b); else return 0; public static void main(String[] args) { 第 18 页
展开阅读全文

开通  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 

客服