收藏 分销(赏)

java复习题——2.doc

上传人:pc****0 文档编号:7451952 上传时间:2025-01-05 格式:DOC 页数:7 大小:53.50KB
下载 相关 举报
java复习题——2.doc_第1页
第1页 / 共7页
java复习题——2.doc_第2页
第2页 / 共7页
点击查看更多>>
资源描述
Java复习题二 一、选择题(每小题2分,共70分) (1)用于设置组件大小的方法是( B ) A)paint( ) B)setSize( ) C)getSize( ) D)repaint( ) (2)点击窗口内的按钮时,产生的事件是( C ) A)MouseEvent B)WindowEvent C)ActionEvent D)KeyEvent (3)AWT中用来表示对话框的类是( D ) A)Font B)Color C)Panel D)Dialog (4)下列运算符中,优先级最高的是( D ) A)+= B)= = C)&& D)++ (5)下列运算结果为1的是( B ) A)8>>1 B)4>>>2 C)8<<1 D)4<<<2 (6)下列语句中,可以作为无限循环语句的是(A ) A)for(;;) {} B)for(int i=0; i<10000;i++) {} C)while(false) {} D)do {} while(false) (7)下列表达式中,类型可以作为int型的是( C ) A)“abc”+”efg” B)“abc”+’efg’ C)‘a’+’b’ D)3+”4” (8)阅读下列程序 Public class Test implements Runnable{ Private int x=0; Private int y=o; boolean flag=true; Public static void main(string[ ] args) { Test r =new Test( ); Thead t1=new Thead(r); Thead t2=new Thead(r); t1.start( ); t2.start( ); } Public void run(){ While(flag) { x++; y++; system.out.println(“(” +x_ “,”+y+”)”); if (x>=10) flag=false; } } } 下列对程序运行结果描述的选项中,正确的是( B ) A)每行的(x,y)中,可能有;每一对(x,y)值都出现两次。 B)每行的(x,y)中,可能有;每一对(x,y)值仅出现一次。 C)每行的(x,y)中,可能有x=y;每一对(x,y)值都出现两次。 D)每行的(x,y)中,可能有x=y;每一对(x,y)值都出现一次。 (9)如果线程正处于运行状态,则它可能到达的下一个状态是(C ) A)只有终止状态 B)只有阻塞状态和终止状态 C)可运行状态,阻塞状态,终止状态 D)其他所有状态 (10)在下列程序的空白处,应填入的正确选项是( B ) import java.io.*; Public class writeInt{ Public static void main(string[ ] a) { Int[ ] myArray = {10,20,30,40}; try{ DataOutputSystem dos= new DataOutputSystem (new FileOutputSystem(“ints.dat”)); for (int i=0;Idos。writeInt(myArray[i]); dos. System.out.println(“Have written binary file ints.dat”); } catch(IOException ioe) { System.out.println(“IO Exception”); } } } A)start( ) B)close( ) C)read( ) D)write( )    (11)在一个线程中调用下列方法,不会改变该线程运行状态的是( B) A)yield方法 B)另一个线程的join方法 C)sleep方法 D)一个对象的notify方法 (12)在关闭浏览器时调用,能够彻底终止Applet并释放该Applet所有资源的方法是( B ) A)stop( ) B)destroy( ) C)paint( ) D)start( ) (13)下列变量名的定义中,符合Java命名约定的是( A ) A)fieldname B)super C)Intnum D)$number (14)自定义异常类的父类可以是( C ) A)Error B)VirtuaMachineError C)Exception D)Thread (15)阅读下列程序片段 Public void test(){ Try{ sayHello(); system.out.println(“hello”); } catch (ArrayIndexOutOfBoundException e) { System.out.println(“ArrayIndexOutOfBoundException”); }catch(Exception e){ System.out.println(“Exception”); }finally { System.out.println(“finally”); } } 如果sayHello( )方法正常运行,则test( )方法的运行结果将是( D ) A)Hello B)ArrayIndexOutOfBondsException C)Exception Finally D)Hello Finally (16)为使Java程序独立于平台,Java虚拟机把字节码与各个操作系统及硬件( A ) A)分开 B)结合 C)联系 D)融合 (17)Java中的基本数据类型int在不同的操作系统平台的字长是( B ) A)不同的 B)32位 C)64位 D)16位 (18)String、StingBuffer都是__C___类,都不能被继承。 A)static B)abstract C)final D)private (19)下列程序的功能是统计字符串中“array”的个数,在程序的空白处应填入的正确选项是(D ) public class FindKeyWords{ public static void main(sring[] args){ sting text= “ An array is a data structur that stores a collection of” + “values of the same type . You access each individual value” + “through an integer index . For example,if a is an array” + “of inergers, then a[i] is the ith integer in the array.”; Int arrayCount =0; Int idex = -1; Sting arrarStr =”array”; Index = text.indexof(arrayStr); While(index 0) { ++arrayCount; arrayStr.length(); Index = text.indexof(arrayStr,index); } System.out.println(“the text contains” + arrayCount + “arrays”); } } A)< B)= C)<= D)>= (20)构造方法名必须与___A___相同,它没有返回值,用户不能直接调用它,只能通过new调用。 A)类名 B)对象名 C)包名 D)变量名 (21)在多线程并发程序设计中,能够给对象x加锁的语句是( B ) A)x.wait( ) B)synchronized(x) C)x.notify( ) D)x.synchronized( ) (22)Java中类ObjectOutputStream支持对象的写操作,这是一种字节流,它的直接父类是( C ) A)Writer B)DataOutput C)OutputStream D)ObjectOutput (23)在下列程序的空白处,应填入的正确选项是D Import java.io.*; Pulilc class ObjectStreamTest{ Publilc static void main(string args[]) throws IOException{ ObjectOutputStream oos= new ObjectOutputStream (new FileOutputStream(“serial.bin”)); Java.util.Date d= new Java.util.Date(); Oos (d); ObjectInputStream ois= new ObjectInputStream(new FileOutputStream(“serial.bin”)); try{ java.util.date restoredDate =(Java.util.Date) ois.readObject(); System.out.println(“read object back from serial.bin file:”+ restoredDate); } Catch (ClassNotFoundException cnf) { System.out.println (“class not found”); } } A)WriterObject B)Writer C)BufferedWriter D)WriterObject (24)Class类的对象由__A____自动生成,隐藏在.class文件中,它在运行时为用户提供信息。 A)Java编译器 B)Java解释器 C)Java new 关键字 D)Java类分解器 二、填空题(每空2分,共30分) (1在多线程程序设计中,如果采用继承Thread类的方式创建线程,则需要重写Thread类的 【1】( )方法。 (2)在下列Java applet 程序的横线处填入代码,使程序完整并能够正确运行。 Import java. awt. *; Import java. applet. *; Public class Greeting extends applet{ Public void 【2】 (Graphics g) { g.drawSting(“how are you!”,10,10); } } (3)在Java语言中,用 【3】 修饰符定义的类为抽象类。 (4)在Java中,字符是以16位的 【4】 码表示。 (5)请在下列程序的空白处,填上适当的内容: Import java. awt. *; Import java. util. *; Class BufferTest{ Public static void main(string args[])Throws IOException{ FileOutputStream unbuf=new FileOutputStream(“test.one”) ; BufferedOutputStream buf=new 【5】 (new FileOutputStream(“test.two”)); System.out.println(“write file unbuffered: ” + time(unbuf) + “ms”); System.out.println(“write file buffered: ” + time(buf) + “ms”); } Static int time (OutputStream os)Throws IOException{ Date then = new Date(); for (int i=0; i<50000; i++){ os.write(1); } } os.close(); return(int)(()new Date()).getTime() - then.getTime()); } (6)代码System.out.println(066)的输出结果是 【6】。 (7)Swing中用来表示工具栏的类是 javax.swing. 【7】 。 (8)表达式(10*49.3)的类型是 【8】 型。 (9)抛出异常的语句是 【9】 语句。 答案: 一、选择题 1-5:BCDDB 6-10: ACBCB 11-15:BBACD 16-20: ABCDA 21-24: BCDA 二、填空题 1. Run() 2. Paint 3. Abstract 4. Unicode 5. BufferedOutputStream 6. 54 7. JtoolBar 8. double 9. throwException
展开阅读全文

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

客服