收藏 分销(赏)

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

上传人:二*** 文档编号:4526458 上传时间:2024-09-26 格式:DOC 页数:12 大小:42.54KB
下载 相关 举报
2021年JAVA语言程序设计期末考试试题及答案应考必备题库六.doc_第1页
第1页 / 共12页
本文档共12页,全文阅读请下载到手机保存,查看更方便
资源描述
<p>《JAVA语言程序设计》期末考试试题及答案6(应考必备题库) 一、填空题 1.定义类保存字是( &nbsp;class &nbsp;),定义接口保存字是( &nbsp; interface &nbsp; &nbsp;)。 2.Socket普通也称为 ( &nbsp;套接字 &nbsp;),用于描述( &nbsp;IP地址 ) &nbsp;和 ( 端口 )。 3.线程优先级在( &nbsp;1 &nbsp;)至( &nbsp;10 &nbsp;)之间,数值越大( 任务越紧急 )。 4.构造办法是一种特殊成员办法,构造办法名与( 类名 ) 相似。 5.Java语言只容许单继承,指每个类只能有一种 ( 父类 )。 6.Java源程序扩展名是( .java ),通过编译后程序扩展名是( .class )。 7. 在一种时间只能由一种线程访问资源称为 ( 临界资源 ) 。访问临界资源代码( 临界代码 )。 8. 在多线程系统中,各种线程之间有 ( 同步 ) 和 ( 互斥 ) 两种关系。 二、选取题 1.关于选取构造下列哪个说法对的? (  ) A.if语句和 else语句必要成对浮现 B.if语句可以没有else语句相应 C.switch构造中每个case语句中必要用break语句 D.switch构造中必要有default语句 2.while循环和 do…while循环区别是:  (  ) A.没有区别,这两个构造任何状况下效果同样 B.while循环比 do…while循环执行效率高 C.while循环是先循环后判断,因此循环体至少被执行一次 D.do…while循环是先循环后判断,因此循环体至少被执行一次 3.关于 for循环和 while循环说法哪个对的? (  ) A.while循环先判断后执行,for循环先执行后判断。 B.while循环判断条件普通是程序成果,for循环判断条件普通是非程序成果 C.两种循环任何时候都不可以替代 D.两种循环构造中都必要有循环体,循环体不能为空 4.下列修饰符中与访问控制无关是 (  ) A.private    &nbsp; B.public C.protected D.final 5. void含义:  (  ) A.办法没有返回值    B. 办法体为空 C.没故意义     &nbsp; &nbsp; D. 定义办法时必要使用 6. return语句:  (  ) A.只能让办法返回数值     B.办法都必要具有 C.办法中可以有多句return    D.不能用来返回对象 7.关于对象成员占用内存说法哪个对的?  (  ) A.同一种类对象共用同一段内存 B、同一种类对象使用不同内存段,但静态成员共享相似内存空间 C.对象办法不占用内存 D.以上都不对 8.下列说法哪个对的? A.不需要定义类,就能创立对象 B.对象中必要有属性和办法 C.属性可以是简朴变量,也可以是一种对象 D、属性必要是简朴变量 9.下列说法哪个对的?  (  ) A、一种程序可以包括各种源文献 B、一种源文献中只能有一种类 C、一种源文献中可以有各种公共类 D、一种源文献只能供一种程序使用 10.关于办法main()说法哪个对的?(  ) A.办法main()只能放在公共类中 B &nbsp;main()头定义可以依照状况任意更改 C.一种类中可以没有main()办法 D.所有对象创立都必要放在main()办法中 11.构造函数何时被调用?  (  ) A、创立对象时      B、类定义时 C、使用对象办法时   D、使用对象属性时 12.&nbsp;抽象办法:  (  ) A、可以有办法体 B、可以出当前非抽象类中 C、是没有办法体办法 D、抽象类中办法都是抽象办法  13.关于继承说法对的是:  (  ) A、子类将继承父类所有属性和办法。 B、子类将继承父类非私有属性和办法。 C、子类只继承父类public办法和属性 D、子类只继承父类办法,而不继承属性 14.关于构造函数说法哪个对的?  (  ) A、一种类只能有一种构造函数 B、一种类可以有各种不同名构造函数 C、构造函数与类同名 D、构造函数必要自己定义,不能使用父类构造函数 15. this和super: A、都可以用在main()办法中 B、都是指一种内存地址 C、不能用在main()办法中 D、意义相似 16.关于super说法对的是: A、是指当前对象内存地址 B、是指当前对象父类对象内存地址 C、是指当前对象父类 D、可以用在main()办法中 17.覆盖与重载关系是  (  ) A、覆盖只有发生在父类与子类之间,而重载可以发生在同一种类中 B.覆盖办法可以不同名,而重载办法必要同名 C.final修饰办法可以被覆盖,但不能被重载 D.覆盖与重载是同一回事 18.关于接口哪个对的?  (  ) A、实现一种接口必要实现接口所有办法 B.一种类只能实现一种接口 C.接口间不能有继承关系 D.接口和抽象类是同一回事 19.异常包括下列哪些内容?  (  ) A.程序执行过程中遇到事先没有预料到状况 B.程序中语法错误   C.程序编译错误 D.以上都是 20.&nbsp;&nbsp;&nbsp;对于已经被定义过也许抛出异常语句,在编程时:  (  ) A、必要使用try/catch语句解决异常,或用throws将其抛出 B.如果程序错误,必要使用 try/catch语句解决异常 C.可以置之不理 D.只能使用try/catch语句解决 21.&nbsp;&nbsp;字符流与字节流区别在于(  ) A.前者带有缓冲,后者没有 B.前者是块读写,后者是字节读写 C. 两者没有区别,可以互换使用 D. 每次读写字节数不同 22.下列流中哪个不属于字节流  (  ) A.FileInputStream B.BufferedInputStream C. FilterInputStream D. InputStreamReader是字符 三、程序填空题 1.public class Sum{ public static void main(String [] args){ int j=10; System.out.println(&quot;j is :&quot;+j); calculate(j); System.out.println(&quot;At last,j is :&quot;+j); } static void calculate (int j){/////////虽然办法是静态但是数据不是静态 for (int i = 0;i&lt;10;i++) j++; System.out.println(&quot;j in calculate() is:&quot;+j); } } 输出成果为: j is :&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(1) j in calculate() is : &nbsp; &nbsp;(2) At last j is :&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(3) 答案:(1) 10; (2) 20; (3) 10。 2. 按规定填空 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()); } } 在以上这段程序中: 抽象类有:SuperAbstract和 (1)  (写出类名) 非抽象类有:       (2)  (写出类名) 接口有:         (3)  (写出接口名) AsSuper中x()办法是(4)办法,因此在InheritAbstract中必要对它进行(5)        答案: (1) SuperAbstract; (2) InheritAbstract; (3) AsSuper; (4) 抽象; (5) 覆盖和实现。 3. 按注释完毕程序 public class Leaf { private int i = 0;//此属性值用于检查 Leaf increment(){ //定义办法increment(),返回值是Leaf类对象 i++; return (1) ;//将当前对象地址作为返回值返回 } void print() { System.out.println(&quot; i = &quot; + i); } public static void main(String args[]){ Leaf x = &nbsp;(2);//创立Leaf类对象x x.increment().increment().increment().print(); }//多次调用办法increment(),返回都是x地址,i 值表达调用次数 } 输出成果为 i = &nbsp;(3) &nbsp; &nbsp; &nbsp; 答案: (1) this; (2) new Leaf(); (3) 3 4.&nbsp;&nbsp;按注释提示完毕文献复制程序 //FileStream源代码如下: import java.io.*; class FileStream { public static void main(String args []) { &nbsp; &nbsp; try { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File inFile = new File(&quot;file1.txt&quot;); //指定源文献 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File outFile = new File(&quot;file2.txt&quot;); //指定目的文献 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FileInputStream fis =(1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FileOutputStream fos = new FileOutputStream(outFile); &nbsp; &nbsp; &nbsp; int c; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//逐字节从源文献中输入,再输出到fos流 while ((c = fis.read ())!=-1) &nbsp; &nbsp; (2); &nbsp; &nbsp; &nbsp; &nbsp; fis.close(); &nbsp; &nbsp; &nbsp; fos.close(); } catch (Exception e) { &nbsp; &nbsp; &nbsp;System.out.println(&quot;FileStreamsTest:&quot;+e); } &nbsp; &nbsp; } } 答案: (1) new FileInputStream(inFile); (2) fos.write(c); 5.&nbsp; 阅读程序,给出成果: // AbstractClassDemo.java源代码如下: abstract class Shape { &nbsp; &nbsp; //定义抽象类Shape和抽象办法display abstract void display(); } class Circle extends Shape { void display() { //实现抽象类办法 System.out.println(&quot;Circle&quot;); } } class Rectangle extends Shape { void display() { &nbsp; &nbsp;//实现抽象类办法 System.out.println(&quot;Rectangle&quot;); } } class Triangle extends Shape { void display() { &nbsp; //实现抽象类办法 System.out.println(&quot;Triangle&quot;); } } public class AbstractClassDemo{ public static void main(String args[]){ (new Circle()).display(); //定义无名对象来调用相应display办法 (new Rectangle()).display(); (new Triangle()).display(); } } 输出成果是 ? 答案:(1) Circle; (2) Rectangle; (3) Triangle。</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 

客服