收藏 分销(赏)

2021年JAVA语言程序设计期末考试试题及答案应考必备题库五.doc

上传人:二*** 文档编号:4526449 上传时间:2024-09-26 格式:DOC 页数:10 大小:42.04KB
下载 相关 举报
2021年JAVA语言程序设计期末考试试题及答案应考必备题库五.doc_第1页
第1页 / 共10页
本文档共10页,全文阅读请下载到手机保存,查看更方便
资源描述
<p>《JAVA语言程序设计》期末考试试题及答案5(应考必备题库) 一、 单选题 1、当某一线程正处在休眠状态,而另一种线程用 Thread 类中 interrupt() 办法中断它时,抛出异常类型是( &nbsp; &nbsp;)。 A) IOException &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; B) RuntimeException C) InterruptedException &nbsp; &nbsp; D) ClassNotFoundException &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2、下面程序段功能是( &nbsp;)。 File file1=new File(&quot;d:\\xxx\\yyy\\zzz&quot;); file1.mkdirs(); A)在当前目录下生成子目录:\xxx\yyy\zzz &nbsp; &nbsp; B)生成目录: e:\xxx\yyy\zzz C)在当前目录下生成文献xxx.yyy.zzz &nbsp; &nbsp; &nbsp; &nbsp; D)以上说法都不对 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3、应用程序main办法中有如下语句,则输出成果是 ( &nbsp; )。 String s = &quot;xxxxxxxxxxxxxxx#123#456#zzzzz&quot;; int n = s.indexOf(&quot;#&quot;); &nbsp; &nbsp; int k = s.indexOf(&quot;#&quot;,n+1); String s2 = s.substring(n+1,k); System.out.println(s2); A) 123456 &nbsp; &nbsp; B) 123 &nbsp; &nbsp; C) xxxxxxxxxxxxxxx &nbsp; &nbsp; &nbsp;D) zzzzz &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4、关于下面程序Test.java说法对的是( &nbsp; &nbsp;)。 public class Test { &nbsp; &nbsp;String x=&quot;1&quot;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int y; &nbsp; &nbsp;public static void main(String args[]) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int z=2; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(x+y+z); &nbsp; &nbsp;} &nbsp; } A)3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; B)102 &nbsp; &nbsp; &nbsp; &nbsp;C) 12 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;D)程序有编译错误 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 5、应用程序main办法中有如下语句,则输出成果是 ( &nbsp; )。 int &nbsp;b[][]={{1,1,1},{2,2},{3}}; &nbsp; &nbsp; &nbsp; &nbsp;int sum=0; &nbsp; &nbsp; &nbsp; &nbsp;for(int i=0;i&lt;b.length;i++) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for(int j=0;j&lt;b[i].length;j++) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sum+=b[i][j]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;sum=&quot;+sum); A) 10 &nbsp; &nbsp; B)6 &nbsp; &nbsp; C) 9 &nbsp; &nbsp; D) 13 &nbsp; &nbsp; &nbsp; 6、应用程序main办法中有如下语句,则执行后输出成果是 ( &nbsp; )。 int[] x = {125,21,5,168,98}; int min = x[0]; for (int i=1;i&lt;x.length;i++){ if(x[i] &lt; min) min = x[i]; } System.out.println(min); A) 125 &nbsp; &nbsp; B) 5 &nbsp; &nbsp; C) 98 &nbsp; &nbsp; &nbsp; &nbsp;D) 168 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 7、应用程序main办法中有如下语句,则输出成果是 ( &nbsp; )。 Hashtable hashtable=new Hashtable(); hashtable.put(&quot;100&quot;,&quot;aaa&quot;); hashtable.put(&quot;200&quot;,&quot;bbb&quot;); hashtable.put(&quot;300&quot;,&quot;ccc&quot;); System.out.println(hashtable.get(&quot;300&quot;).toString() + hashtable.get(&quot;200&quot;).toString() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + hashtable.get(&quot;100&quot;).toString()); &nbsp; &nbsp; &nbsp; A) aaa &nbsp; B) bbb &nbsp; &nbsp;C) ccc &nbsp; D) cccbbbaaa &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 8、如下关于java异常说法不对的是( &nbsp;)。 A) Throwable 类是 Java 语言中Error类和Exception类父类。 B)当异常对象是Exception类(或其子类)实例时,能通过 Java 虚拟机或者 throw 语句抛出该异常对象,并能通过try…catch…finally解决。 C)如果只用一种catch块捕获各种异常对象,则catch 子句中参数类型应是所有异常对象父类。 D)以上说法都不对。 9、下面程序创立了一种文献输出流对象,用来向文献test.txt中输出数据,假设程序当前目录下不存在文献test.txt,编译下面程序Test.java后,将该程序运营3次,则文献test.txt 内容是( &nbsp;)。 import java.io.*; public class Test { public static void main(String args[]) { try { String s=&quot;ABCDE&quot;; byte b[]=s.getBytes(); FileOutputStream file=new FileOutputStream(&quot;test.txt&quot;,true); file.write(b); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; file.close(); } catch(IOException e) { System.out.println(e.toString()); } } } A) ABCABC &nbsp; B) ABCDE &nbsp; &nbsp; C)Test &nbsp; &nbsp;D) ABCDE ABCDE ABCDE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 10、下面说法不对的是( &nbsp;)? A)列表(List)、集合(Set)和映射(Map)都是java.util包中接口。 B)List接口是可以包括重复元素有序集合。 C)Set接口是不包括重复元素集合。 D)Map接口将键映射到值,键可以重复,但每个键最多只能映射一种值。 二、多选题 1、下面哪些核心字能用来控制对类成员访问( &nbsp;)? A) public &nbsp; B) protected &nbsp; &nbsp;C) private &nbsp; &nbsp; D) default &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2、下面关于Java中异常解决try块说法对的是( &nbsp; &nbsp;)? A) try块后普通应有一种catch 块,用来解决try块中抛出异常。 &nbsp; B) catch 块后必要有finally块。 C)也许抛出异常办法调用应放在try块中。 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; D)对抛出异常解决必要放在try块中 3、线程对象生命周期中,普通经历下面哪些状态( &nbsp; &nbsp; )。 A)新建 &nbsp; &nbsp; &nbsp;B)运营 &nbsp; &nbsp; &nbsp;C)就绪 &nbsp; &nbsp; &nbsp;D)死亡 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4、定义如下二维数组b,下面说法对的是( &nbsp;)。 int b[][]={{1,2,3},{4,5},{6,7,8}}}; A)b.length值是3。 &nbsp; B)b[1].length值是3。 C)b[1][1]值是5。 &nbsp; D) 二维数组b第一行有3个元素 &nbsp; 5、类B是一种抽象类,类C是类B非抽象子类,下列创立对象x1语句中对的是( &nbsp; )。 A) B x1= new B( ); &nbsp; &nbsp; &nbsp; B) B x1= new C( ); &nbsp; C) C x1=new C( ); &nbsp; &nbsp; &nbsp; &nbsp;D) C x1= new B( ); 6、下面关于进程、线程说法对的是( &nbsp; &nbsp;)。 A)进程是程序一次动态执行过程。一种进程在其执行过程中,可以产生各种线程——多线程,形成多条执行线索。 B)线程是比进程更小执行单位,是在一种进程中独立控制流,即程序内部控制流。线程自身不能自动运营,栖身于某个进程之中,由进程启动执行。 C)Java多线程运营与平台有关。 D)对于单解决器系统,各种线程分时间片获取CPU或其她系统资源来运营。对于多解决器系统,线程可以分派到各种解决器中,从而真正并发执行多任务。 7、下面关于外部类和内部类成员互相访问规则中,对的选项是( &nbsp; &nbsp;)。 A)内部类可以直接访问外部类成员 B)外部类可以直接访问内部类成员 C)外部类不能访问内部类成员 D)外部类可通过创立内部类实例来访问内部类成员 三、程序阅读题 1、阅读下面程序代码,并回答问题(u问3分,v问3分,共6分)。 String s1 = new String(&quot;abcde&quot;); String s2 = new String(&quot;abcde&quot;); boolean b1= s1.equals(s2); boolean b2 = s1== s2; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.print(b1+&quot; &nbsp; &quot;+b2); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u程序段执行后,在命令行输出成果如何? v解释输出(1)成果因素? 答案: u true &nbsp;false vequals办法比较两个字符串内容与否相等;运算符“==”判断两个对象与否指向同一种引用,即与否为同一种对象。 2、阅读下面程序,并回答问题(u问3分,v问3分,共6分)。 import java.io.*; public class Test { &nbsp; &nbsp;public static void main(String args[]) throws IOException { &nbsp; &nbsp; &nbsp; &nbsp;BufferedReader buf=new BufferedReader( &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;new InputStreamReader(System.in)); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while(true) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String str = buf.readLine(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(str.equals(&quot;quit&quot;)) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int x=Integer.parseInt(str); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(x*x); &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp;} &nbsp; } 编译运营上面程序: u从键盘输入10,回车后输出成果如何? v从键盘输入exit,回车后程序能对的执行吗?为什么? 答案: u100 &nbsp; v不能;由于办法Integer.parseInt(str)不能将字符串“exit”转化为整数,抛出异常。 3、写出下面程序编译、运营后成果(6分)。 public class Test{ &nbsp; &nbsp; public static void main(String args[]) { &nbsp; &nbsp; &nbsp; &nbsp; new Student(&quot;Tom&quot;,&#39;m&#39;,90,88); &nbsp; &nbsp; &nbsp; &nbsp; new Student(&quot;Jack&quot;,&#39;m&#39;,66,89); &nbsp; &nbsp; &nbsp; &nbsp; new Student(&quot;Mary&quot;,&#39;f&#39;,76,86); &nbsp; &nbsp; &nbsp; &nbsp; System.out.println(&quot;name\tsex\tchinese\tenglish&quot;); &nbsp; &nbsp; &nbsp; &nbsp; Student.print(); &nbsp; &nbsp; } } class Student { &nbsp; &nbsp; protected &nbsp;String &nbsp; name; &nbsp; &nbsp; protected &nbsp;char &nbsp; &nbsp; sex; &nbsp; &nbsp; protected &nbsp;int &nbsp; &nbsp; &nbsp;chinese; &nbsp; &nbsp; protected &nbsp;int &nbsp; &nbsp; &nbsp;english; &nbsp; &nbsp; protected &nbsp;Student &nbsp;next; &nbsp; &nbsp; static Student list; &nbsp; &nbsp; &nbsp; &nbsp; Student (String name,char sex,int chinese,int english) &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; this.name=name; &nbsp; &nbsp; &nbsp; &nbsp; this.sex=sex; &nbsp; &nbsp; &nbsp; &nbsp; this.chinese=chinese; &nbsp; &nbsp; &nbsp; &nbsp; this.english=english; &nbsp; &nbsp; &nbsp; &nbsp; this.next=list; &nbsp; &nbsp; &nbsp; &nbsp; list=this; &nbsp; &nbsp; } &nbsp; &nbsp; static void print() { &nbsp; &nbsp; &nbsp; &nbsp; Student friend=list; &nbsp; &nbsp; &nbsp; &nbsp; if (friend==null) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println(&quot;The list is empty.&quot;); &nbsp; &nbsp; &nbsp; &nbsp; else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; do{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println(friend.toString()); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; friend=friend.next; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }while(friend!=null); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; } &nbsp; &nbsp; public String toString() &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; return new String(name+&quot;\t&quot;+sex+&quot;\t&quot;+chinese+&quot;\t&quot;+english); &nbsp; &nbsp; } } 答案: name &nbsp; &nbsp;sex &nbsp; &nbsp; chinese &nbsp;english Mary &nbsp; &nbsp;f &nbsp; &nbsp; &nbsp; 76 &nbsp; &nbsp; &nbsp;86 Jack &nbsp; &nbsp; m &nbsp; &nbsp; &nbsp;66 &nbsp; &nbsp; &nbsp;89 Tom &nbsp; &nbsp; m &nbsp; &nbsp; &nbsp;90 &nbsp; &nbsp; &nbsp;88</p>
展开阅读全文

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


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手

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

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

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

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

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

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

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

客服