JAVA期末考试试卷及答案(共8页).doc

上传人:飞****2 文档编号:6241387 上传时间:2022-02-01 格式:DOC 页数:8 大小:89.50KB
返回 下载 相关 举报
JAVA期末考试试卷及答案(共8页).doc_第1页
第1页 / 共8页
JAVA期末考试试卷及答案(共8页).doc_第2页
第2页 / 共8页
点击查看更多>>
资源描述

《JAVA期末考试试卷及答案(共8页).doc》由会员分享,可在线阅读,更多相关《JAVA期末考试试卷及答案(共8页).doc(8页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、精选优质文档-倾情为你奉上 二选择题; 1以下哪个方法用于定义线程的执行体?( C )A、start()B、init()C、run()D、synchronized()2下面哪个不是Java中的容器? ( B )A、ScrollPaneB、CanvasC、AppletD、Dialog3下面哪个方法与applet的显示无关?( A )A、draw()B、update()C、repaint()D、paint()4当Frame改变大小时,放在其中的按钮大小不变,则使用如下哪种布局方式? ( A )A、FlowLayoutB、CardLayoutC、BorderLayoutD、GridLayout5有如

2、下代码段: 1) 2) if(unsafe()/do something 3) else if(safe()/do the other 4) 其中,方法unsafe() 将抛出IOException, 请问可将以下哪项填入第1行?(D ) A、public IOException methodName() B、public void methodName() C、public void methodName() throw IOException D、public void methodName() throws IOException6以下哪个关键字可以用来对对象加互斥锁?( B) A、tr

3、ansient B、synchronized C、 serializeD、static7在使用interface声明一个接口时,只可以使用( D )修饰符修饰该接口。A、privateB、protectedC、private protectedD、public8编译并运行以下程序,以下描述哪个选项是正确的( C )1. class A2.protected boolean equals()3.return super.equals();4.A、编译通过运行无异常B、编译通过但运行时出错C、行2出错,不能成功编译D、不能成功编译,行3出错9Java的字符类型采用的是Unicode编码方案,每个U

4、nicode码占用( B )个比特位。A、8 B、16 C、32 D、6410在编写Java Applet程序时,若需要对发生的事件作出响应和处理,一般需要在程序的开头写上( D )语句。A、import java.awt.* ; B、import java.applet.* ;C、import java.io.* ; D、import java.awt.event.* ;11以下关于构造函数的描述错误的是( A )。A、构造函数的返回类型只能是void型。B、构造函数是类的一种特殊函数,它的方法名必须与类名相同。C、构造函数的主要作用是完成对类的对象的初始化工作。D、一般在创建新对象时,系统

5、会自动调用构造函数。12有程序如下,关于程序的描述哪个是正确的?( C )public class Person static int arr = new int10;public static void main(String a) System.out.println(arr1); A、编译将产生错误B、编译时正确,但运行时将产生错误C、正确,输出0D、正确,输出null13有语句String s=”hello world”; ,以下操作哪个是不合法的?( B )A、int i=s.length();B、s=3;C、String ts=s.trim();D、String t=s+”!”;1

6、4给出如下代码:classTestprivateintm;publicstaticvoidfun()/somecode. 如何使成员变量m被函数fun()直接访问?( C )A、将privateintm改为protectedintmB、将privateintm改为publicintmC、将privateintm改为staticintmD、将privateintm改为intm15 Java application中的主类需包含main方法,main方法的返回类型是什么?( D )A、intB、floatC、doubleD、void16有以下方法的定义,请选择该方法的返回类型( D )。Retur

7、nType method(byte x, double y)return (short)x/y*2;A、byteB、shortC、intD、double17下列哪些语句关于Java内存回收的说明是正确的? ( B )A、程序员必须创建一个线程来释放内存B、内存回收程序负责释放无用内存C、内存回收程序允许程序员直接释放内存D、内存回收程序可以在指定的时间释放内存对象18在编写Java Applet程序时,若需要对发生的事件作出响应和处理,一般需要在程序的开头写上( D )语句。A、import java.awt.* ; B、import java.applet.* ;C、import java.

8、io.* ; D、import java.awt.event.* ;19容器Panel和Applet缺省使用的布局编辑策略是( B )A、BorderLayoutB、FlowLayoutC、GridLayoutD、CardLayout20设有下面两个赋值语句: a = Integer.parseInt(“123”); b = Integer.valueOf(“123”).intValue();下述说法正确的是( D )。A、a是整数类型变量,b是整数类对象。B、a是整数类对象,b是整数类型变量。C、a和b都是整数类对象并且值相等。D、a和b都是整数类型变量并且值相等。21编译并运行以下程序,以

9、下描述哪个选项是正确的( C )。1. class A2.protected String toString()3.return super.toString();4.A、编译通过运行无异常B、编译通过但运行时出错C、行2出错,不能成功编译D、不能成功编译,行3出错22有以下程序片段,下列哪个选项不能插入到行1。( D )1.2.public class Interesting3./do sth 4. A、import java.awt.*;B、package mypackage;C、class OtherClass D、public class MyClass 23以下哪个不是Java的关键

10、字?( A )A、TRUEB、constC、superD、void24关于以下application的说明,正确的是( C )。1class StaticStuff2 3static int x;4static x+=5;5public static void main(String args )67 System.out.println(“x=” + x);89static x/=5;10A、4行与9行不能通过编译,因为缺少方法名和返回类型B、9行不能通过编译,因为只能有一个静态初始化器C、编译通过,执行结果为:x=1D、能通过编译,但程序运行结果不可预知,因为变量x没有初始化25Filte

11、rOutputStream是BufferedOutputStream、DataOutputStream及PrintStream的父类,以下哪个类可能是FilterOutputStream构造函数的参数类型?(BA、OutputStreamB、FileC、InputStreamD、BufferedOutputStream26在使用interface声明一个接口时,只可以使用(D )修饰符修饰该接口。A、privateB、protectedC、private protectedD、public27有程序片段如下,以下哪个表示式的结果为true?( B )Float s=new Float(0.1f

12、);Float t=new Float(0.1f);Double u=new Double(0.1);A、s=tB、s.equals(t)C、u.equals(s)D、t.equals(u)三程序阅读题1写出以下程序的运行结果。(54321)public class TestArray public static void main(String args ) int i , j ;int a = 1,3,2,5,4; for ( i = 0 ; i a.length-1; i + ) int k = i; for ( j = i ; j ak ) k = j; int temp =ai; a

13、i = ak; ak = temp; for ( i =0 ; ia.length; i+ ) System.out.print(ai+ ); System.out.println( ); 2写出以下程序的功能。(在屏幕上输出test.java文件的内容)import java.io.*;class FileIODemopublic static void main(String args) throws IOExceptionint b;FileInputStream fileIn=new FileInputStream(“test.java”);while(b=fileIn.read()!

14、=-1)System.out.print(char)b);3 写出以下程序的运行结果。Str0str1str2 str0str2import java.util.*;public class Vec public static void main(String args) String s; s=new String2; s0=new String(str1); s1=new String(str2); Vector v = new Vector(); for(int i = 0; i 2; i+) v.addElement(si); v.insertElementAt(new String(

15、str0),0); Enumeration e = v.elements(); while(e.hasMoreElements() System.out.print(e.nextElement()+ ); System.out.println(); v.removeElement(str1 ); for(int i = 0; i v.size() ; i+) System.out.print(v.elementAt(i) + ); System.out.println(); 4写出以下程序的运行结果。intclass OverloadDemo void testOverload( int i

16、) System.out.println(“int”); void testOverload(String s) System.out.println(“String”); public static void main(String args ) OverloadDemo a=new OverloadDemo ( ); char ch=x; a.testOverload(ch); 5阅读以下程序,写出输出结果。inSecondclassclass Firstpublic First()aMethod();public void aMethod()System.out.println(“in

17、First class”);public class Second extends Firstpublic void aMethod()System.out.println(“in Second class”);public static void main(String args)new Second( );6写出以下程序的运行结果。class StaticTest static int x=1; int y; StaticTest()y+;public static void main(String args ) StaticTest st=new StaticTest(); System

18、.out.println(x= + x); System.out.println(st.y= + st.y); st=new StaticTest(); System.out.println(st.y= + st.y); static x+;x=2 st y=1 st y=17阅读以下程序:class Exp1 public static void main(String args) String s,s1=;char c;s=args0;for (int i=0;i=a & c=z) s1=s1+Character.toUpperCase(c);elses1=s1+Character.toL

19、owerCase(c);System.out.println(s1);若在dos命令行输入:java Exp1 cHINA,则输出为 JAVA eXP1 China 。8阅读以下程序:import java.io.*;public class AboutFilepublic static void main(String args)BufferedReader b=new BufferedReader (new InputStreamReader(System.in);String s;System.out.flush();s=b.readLine();System.out.println(“

20、String is:”+s);运行以上程序,若从键盘输入: java则输出结果为 String is: java 。9阅读以下程序,写出输出结果。class Animal Animal() System.out.print (Animal ); public class Cat extends Animal Cat() System.out.print (Cat ); public static void main(String args) Cat kitty= new Cat(); Animal Cat10以下程序段的输出结果为 int,int 。class Cruncher void cr

21、unch( int i ) System.out.print(“int”); void crunch(String s) System.out.print(“String”); public static void main(String args )Crunchercrun=new Cruncher ( );char ch=h;int i=12;crun.crunch(ch);System.out.print(“,”);crun.crunch(i); 11阅读以下程序,输出结果为 cooljava 。import java.io.*;public class TestString publi

22、c static void main(String args ) StringC s = new StringC (cool,java); System.out.println(s); class StringC String s1; String s2; StringC( String str1 , String str2 ) s1 = str1; s2 = str2; public String toString( ) return s1+s2;12 以下程序段的输出结果为 1 v0 v1 1 vo 。import java.util.*;public class VecApp publi

23、c static void main(String args) Vector v = new Vector(); for(int i = 0; i 2; i+) v.addElement(v+i); v.insertElementAt(new Integer(1),0); Enumeration e = v.elements(); while(e.hasMoreElements() System.out.print(e.nextElement()+ ); System.out.println(); v.removeElement(v1 ); for(int i = 0; i v.size()

24、; i+) System.out.print(v.elementAt(i) + ); System.out.println(); 四编程题1编写一个输出Welcome to Java World!的Applet程序和嵌入该Applet的HTML页面。 / Welcome.java/Welcome.htmlimport java.applet.*; import java.awt.*; public class Welcome extends Applet public static String str=null; public void init() str=Welcome to Java

25、World !; ; public void paint(Graphics g) g.drawString(str, 10, 50); ; 编写一个完整的JavaApplication程序。包含接口ShapeArea,类Circle、Rectangle、Test,具体要求如下: 接口ShapeArea: 接口方法doublegetArea():求一个形状的面积doublegetPerimeter():求一个形状的周长类Rectangle: 实现ShapeArea接口,并有以下属性和方法: 属性width:double型,表示长方形的宽度height:double型,表示长方形的长度 方法Rec

26、tangle(doublew,doubleh):构造函数toString():输出矩形的描述信息,如“width=1.0,height=2.0,perimeter=6.0,area=2.0”Test类作为主类要完成测试功能 生成Rectangle对象调用对象的toString方法,输出对象的描述信息publicclassTest/主类定义2分 publicstaticvoidmain(Stringargs) Rectangler=newRectangle(1,2); System.out.println(r.toString(); interfaceShapeArea/接口定义2分 publi

27、cabstractdoublegetPerimeter(); publicabstractdoublegetArea();classRectangleimplementsShapeArea doublewidth,height;/属性定义1分 Rectangle(doublew,doubleh) /构造函数定义1分 width=w;height=h; publicdoublegetPerimeter()/1分 return2*(width+height); publicdoublegetArea()/1分 returnwidth*height; publicStringtoString()/2分 returnwidth=+width+,height=+height+ ,perimeter=+getPerimeter()+,area=+getArea(); 专心-专注-专业

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 应用文书 > 教育教学

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com