Java程序设计复习题一、选择题1.下面哪些是java语言中的关键字?A.sizeof B.abstract C.NULL D.Native2.switch语句中表达式的值必须是A.布尔型或字符型 B.整型或字符型 C.整型或布尔型 D.浮点型或整型3.以下程序测试String 类的各种构造方法,试选出其运行效果。
class STR{public static void main(String args[]){String s1=new String();String s2=new String("String 2");char chars[]={'a',' ','s','t','r','i','n','g'};String s3=new String(chars);String s4=new String(chars,2,6);byte bytes[]={0,1,2,3,4,5,6,7,8,9};StringBuffer sb=new StringBuffer(s3);String s5=new String(sb);System.out.println("The String No.1 is "+s1);System.out.println("The String No.2 is "+s2);System.out.println("The String No.3 is "+s3);System.out.println("The String No.4 is "+s4);System.out.println("The String No.5 is "+s5);}}A.The String No.1 isThe String No.2 is String 2The String No.3 is a stringThe String No.4 is stringThe String No.5 is a stringB.The String No.1 isThe String No.2 is String 2The String No.3 is a stringThe String No.4 is tringThe String No.5 is a stringC.The String No.1 isThe String No.2 is String 2The String No.3 is a stringThe String No.4 is strinThe String No.5 is a stringD.以上都不对4.按访问权限从高到低的排列顺序是A.友好的,public,protected, private. B.public,protected,private,友好的.C.public,友好的,protected,private. D.public,protected,友好的,private5.将一个成员变量声明为常量,应采用的修饰符是:A.const B.final C.public D.extends6.当编译和运行下列程序段时,会发生什么?class Base {}class Sub extends Base {}class Sub2 extends Base {}public class CEx{public static void main(String argv[]){Base b = new Base();Sub s = (Sub) b;}}A.通过编译和并正常运行。
B.编译时出现例外。
C.编译通过,运行时出现例外。
7.如果我们在子类中想使用被子类隐藏的父类的成员变量或方法,使用关键字A.this B.class C.super D.super class8.一个Java Applet 程序中必须有一个类是A.抽象类 B.接口 C.Windows类的子类 D.Applet 类的子类9.对于文本框事件源,可以发生的事件是:A.ItemEvent B.ChoiceEvent C.ItemChoiceEvent D.ActionEvent10.请问所有的例外类皆继承哪一个类?A.java.io.Exception B.ng.ThrowableC.ng.Exception D.ng.Error11.下面程序段的执行结果是什么?public class Foo{public static void main(String[] args){try{return;}finally{System.out.println("Finally");}}}A.程序正常运行,但不输出任何结果。
B.程序正常运行,并输出 "Finally"。
C.编译能通过,但运行时会出现一个例外。
D.因为没有catch语句块,所以不能通过编译。
12.编译Java Application 源程序文件产生的字节码文件的扩展名为( )。
A.java B.class C.html D.exe13.下列哪个是合法的Java标识符( )?A.&2 B.123.9 C._2# D.public14.对于文本区事件源,可以发生的事件是A.ItemEvent B.ChoiceEvent C.TextEvent D.ActionEvent15.Button 类创建的一个对象就是一个A.多行文本 B.标签 C.按钮 D.文本框16.FlowLayout 对应的布局将容器中的组件按照A.将容器的空间分为东、西、南、北、中五个区域,中间的区域最大B.加入的先后顺序从左向右排列C.划分成若干行乘若干列的网格区域,组件就位于这些划分出来的小格中D.由用户定制17.请问所有的例外类皆继承哪一个类?A. java.io.Exception B.ng.ThrowableC. ng.Exception D.ng.Error18.List 创建的一个对象就是一个A.多行文本 B.标签 C.滚动列表 D.文本框19.java.awt 包的MunuItem 是Menu 的A.子类 B.父类 C.没有继承关系 D.不在同一个包里20.类的设计要求它的某个成员变量不能被外部类直接访问,应该使用下面的哪些修饰符获得需要的访问控制()?A.public B.default C.protected D.private21.MouseEvent对应的是A.键盘事件 B.窗口事件 C.按钮事件 D.鼠标事件22.当用Thread(Runnable target)创建线程对象时,创建目标对象的类必须要实现A.ActionListener接口 B.Thread接口 C.ItemListener接口 D.Runnable 接口23.指出正确的表达式A.byte=128; B.Boolean=null;C.long l=0xfffL D.double=0.9239d;24.获得一个含有本地机的域名和IP地址的对象,可以使用InetAddress类的A.实例方法getHostName() B.静态方法getLocalHost()C.实例方法getHostAddress() D.静态方法getByName(String s)25.运行下列程序, 会产生什么结果public class X extends Thread implements Runable{public void run(){System.out.println("this is run()");}public static void main(String args[]){Thread t=new Thread(new X());t.start();}}A.第一行会产生编译错误 B.第六行会产生编译错误C.第六行会产生运行错误 D.程序会运行和启动26.要从文件" file.dat"文件中读出第10个字节到变量C中,下列哪个方法适合? A.FileInputStream in=new FileInputStream("file.dat");in.skip(9); int c=in.read();B.FileInputStream in=new FileInputStream("file.dat");in.skip(10); int c=in.read();C.FileInputStream in=new FileInputStream("file.dat");int c=in.read();D.RandomAccessFile in=new RandomAccessFile("file.dat");in.skip(9); int c=in.readByte();27.容器被重新设置大小后,哪种布局管理器的容器中的组件大小不随容器大小的变化而改变?A.CardLayout B.FlowLayout C.BorderLayout D.GridLayout28.给出下面代码:public class Person{static int arr[] = new int[10];public static void main(String a[]){System.out.println(arr[1]);}}哪个语句是正确的?A.编译时将产生错误; B.编译时正确,运行时将产生错误;C.输出零; D.输出空。
29.哪个关键字可以对对象加互斥锁?A.transient B.synchronized C.serialize D.static30.下列哪些语句关于内存回收的说明是正确的?A.程序员必须创建一个线程来释放内存; B.内存回收程序负责释放无用内存C.内存回收程序允许程序员直接释放内存 D.内存回收程序可以在指定的时间释放内存对象二、填空题1.一个Java源程序是由若干个_______组成的。
2.关系运算符的运算结果是_______。
3.类是用来定义对象的_______。
4.局部变量只在定义它的_______内有效。
5.创建一个对象包括_______和为对象分配内存两个步骤。
6.不用private,public ,protected 修饰符的成员变量称为_______。