1、Java复习题二一、选择题(每小题2分,共70分)(1)用于设置组件大小的方法是( B )A)paint( )B)setSize( )C)getSize( )D)repaint( )(2)点击窗口内的按钮时,产生的事件是( C )A)MouseEventB)WindowEventC)ActionEventD)KeyEvent(3)AWT中用来表示对话框的类是( D )A)FontB)ColorC)PanelD)Dialog(4)下列运算符中,优先级最高的是( D )A)+=B)= =C)&D)+(5)下列运算结果为1的是( B )A)81B)42C)81D)42 (6)下列语句中,可以作为无限
2、循环语句的是(A )A)for(;) B)for(int i=0; i=10)flag=false;下列对程序运行结果描述的选项中,正确的是( B )每行的(x,y)中,可能有;每一对(x,y)值都出现两次。)每行的(x,y)中,可能有;每一对(x,y)值仅出现一次。)每行的(x,y)中,可能有x=y;每一对(x,y)值都出现两次。)每行的(x,y)中,可能有x=y;每一对(x,y)值都出现一次。(9)如果线程正处于运行状态,则它可能到达的下一个状态是(C )A)只有终止状态B)只有阻塞状态和终止状态C)可运行状态,阻塞状态,终止状态D)其他所有状态(10)在下列程序的空白处,应填入的正确选项
3、是( B )import java.io.*;Public class writeIntPublic static void main(string a) Int myArray = 10,20,30,40;tryDataOutputSystem dos= new DataOutputSystem(new FileOutputSystem(“ints.dat”));for (int i=0;Idos。writeInt(myArrayi);dos.System.out.println(“Have written binary file ints.dat”);catch(IOException i
4、oe) 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)fieldnameB)superC)
5、IntnumD)$number(14)自定义异常类的父类可以是( C )A)ErrorB)VirtuaMachineErrorC)ExceptionD)Thread (15)阅读下列程序片段Public void test()TrysayHello();system.out.println(“hello”); catch (ArrayIndexOutOfBoundException e) System.out.println(“ArrayIndexOutOfBoundException”);catch(Exception e)System.out.println(“Exception”);fi
6、nally System.out.println(“finally”);如果sayHello( )方法正常运行,则test( )方法的运行结果将是( D )Hello)ArrayIndexOutOfBondsException)ExceptionFinally)HelloFinally(16)为使Java程序独立于平台,Java虚拟机把字节码与各个操作系统及硬件( A )A)分开B)结合C)联系D)融合(17)Java中的基本数据类型int在不同的操作系统平台的字长是( B )A)不同的B)32位C)64位D)16位(18)String、StingBuffer都是_C_类,都不能被继承。A)s
7、taticB)abstractC)finalD)private (19)下列程序的功能是统计字符串中“array”的个数,在程序的空白处应填入的正确选项是(D )public class FindKeyWordspublic 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
8、. For example,if a is an array”+ “of inergers, then ai 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” + a
9、rrayCount + “arrays”);)=)= (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)WriterB)DataOutputC)OutputStreamD)ObjectOutput(23)在下列程序的空白
10、处,应填入的正确选项是DImport java.io.*;Pulilc class ObjectStreamTestPublilc static void main(string args) throws IOExceptionObjectOutputStream oos= new ObjectOutputStream(new FileOutputStream(“serial.bin”);Java.util.Date d= new Java.util.Date();Oos (d);ObjectInputStream ois=new ObjectInputStream(new FileOutpu
11、tStream(“serial.bin”);tryjava.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)WriterObjectB)WriterC)ufferedWriterD)WriterObject(24)Class类的对
12、象由_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 appletPublic void 【2】 (Graphics g)
13、g.drawSting(“how are you!”,10,10);(3)在Java语言中,用 【3】 修饰符定义的类为抽象类。(4)在Java中,字符是以位的 【4】 码表示。(5)请在下列程序的空白处,填上适当的内容:Import java. awt. *;Import java. util. *;Class BufferTestPublic static void main(string args)Throws IOExceptionFileOutputStream unbuf=new FileOutputStream(“test.one”) ;BufferedOutputStream
14、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 IOExceptionDate then = new Date();for (int i=0; i50000; i+)os.write(1);os.close();re
15、turn(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:BCDDB6-10: ACBCB11-15:BBACD16-20: ABCDA21-24: BCDA二、填空题1 Run()2 Paint3 Abstract4 Unicode 5 BufferedOutputStream6 547 JtoolBar8 double 9 throwException