System.out.println(ar[i]);
}
}
A.打印5个0。
B.编译出错,数组ar[]必须初始化。
C.编译出错,Mine应声明为abstract。
D.出现IndexOutOfBoundes的例外。
10.请问所有的例外类皆继承哪一个类?
A.java.io.ExceptionB.java.lang.Throwable
C.java.lang.ExceptionD.java.lang.Error
11.下面程序段的执行结果是什么?
publicclassFoo{
publicstaticvoidmain(String[]args){
try{
return;}
finally{System.out.println("Finally");
}
}
}
A.程序正常运行,但不输出任何结果。
B.程序正常运行,并输出"Finally"。
C.编译能通过,但运行时会出现一个例外。
D.因为没有catch语句块,所以不能通过编译。
12.编译Java Application源程序文件产生的字节码文件的扩展名为( )。
A.javaB.class
C.htmlD.exe
13.下列哪个是合法的Java标识符( )?
A.&2B.123.9
C._2#D.public
14.设有下面两个类的定义:
class Person{long id; //身份证号
String name; //姓名}
classStudent extends Person{int score; //入学总分
int getScore(){return score;}}
问:
类Person和类Student的关系是( )。
A.包含关系B.继承关系
C.关联关系D.无关系,上述类定义有语法错误
15.在使用interface声明一个接口时,只可以使用( )修饰符修饰该接口。
A.privateB.protected
C.private protectedD.public
16.在编写异常处理的Java程序中,每个catch语句块都应该与( )语句块对应,使得用该语句块来启动Java的异常处理机制。
A.if–elseB.switch
C.tryD.throw
17.请问所有的例外类皆继承哪一个类?
A.java.io.ExceptionB.java.lang.Throwable
C.java.lang.ExceptionD.java.lang.Error
18.paint()方法使用哪种类型的参数?
A.GraphicsB.Graphics2D
C.StringD.Color
19.指出正确的表达式
A.byte=128;B.Boolean=null;
C.longl=0xfffL;D.double=0.9239d;
20.类的设计要求它的某个成员变量不能被外部类直接访问,应该使用下面的哪些修饰符获得需要的访问控制()?
A.publicB.default
C.protectedD.private
21.欲构造ArrayList类的一个实例,此类继承了List接口,下列哪个方法是正确的?
A.ArrayListmyList=newObject();
B.ListmyList=newArrayList();
C.ArrayListmyList=newList();
D.ListmyList=newList();
22.paint()方法使用哪种类型的参数?
A.GraphicsB.Graphics2D
C.StringD.Color
23.指出正确的表达式
A.byte=128;B.Boolean=null;
C.longl=0xfffLD.double=0.9239d;
24.指出下列程序运行的结果
publicclassExample{
Stringstr=newString("good");
char[]ch={'a','b','c'};
publicstaticvoidmain(Stringargs[]){
Exampleex=newExample();
ex.change(ex.str,ex.ch);
System.out.print(ex.str+"and");
Sytem.out.print(ex.ch);
}
publicvoidchange(Stringstr,charch[]){
str="testok";
ch[0]='g';
}
}
A.goodandabcB.goodandgbc
C.testokandabcD.testokandgbc
25.运行下列程序,会产生什么结果
publicclassXextendsThreadimplementsRunable{
publicvoidrun(){
System.out.println("thisisrun()");
}
publicstaticvoidmain(Stringargs[])
{
Threadt=newThread(newX());
t.start();
}
}
A.第一行会产生编译错误B.第六行会产生编译错误
C.第六行会产生运行错误D.程序会运行和启动
26.要从文件"file.dat"文件中读出第10个字节到变量C中,下列哪个方法适合?
A.FileInputStreamin=newFileInputStream("file.dat");
in.skip(9);intc=in.read();
B.FileInputStreamin=newFileInputStream("file.dat");
in.skip(10);intc=in.read();
C.FileInputStreamin=newFileInputStream("file.dat");
intc=in.read();
D.RandomAccessFilein=newRandomAccessFile("file.dat");
in.skip(9);intc=in.readByte();
27.容器被重新设置大小后,哪种布局管理器的容器中的组件大小不随容器大小的变化而改变?
A.CardLayoutB.FlowLayout
C.BorderLayoutD.GridLayout
28.给出下面代码:
publicclassPerson{
staticintarr[]=newint[10];
publicstaticvoidmain(Stringa[])
{
System.out.println(arr[1]);
}
}
哪个语句是正确的?
A.编译时将产生错误;B.编译时正确,运行时将产生错误;
C.输出零;D.输出空。
29.哪个关键字可以对对象加互斥锁?
A.transientB.synchronized
C.serializeD.static
30.下列哪些语句关于内存回收的说明是正确的?
A.程序员必须创建一个线程来释放内存;
B.内存回收程序负责释放无用内存
C.内存回收程序允许程序员直接释放内存
D.内存回收程序可以在指定的时间释放内存对象
二、填空题
1.分析下面一段程序:
classAclass
{
voidgo(){System.out.println("Aclass"); }
}
publicclassBclassextendsAclass
{
voidgo(){System.out.println("Bclass");}
publicstaticvoidmain(Stringargs[])
{
Aclassa=newAclass();
Aclassa1=newBclass();
a.go();
a1.go();
}
}
程序运行结果是:
2.指出下列程序的运行结果
publicclassA1
{
publicstaticvoidmain(Stringargs[])
{
inti=9;
switch(i)
{
default:
System.out.println("default");
case0:
System.out.println("zero");break;
case1:
System.out.println("one");
case2:
System.out.println("two");
}
}
}
程序运行结果是:
3.下面程序段的执行结果是什么?
publicclassFoo
{
publicstaticvoidmain(String[]args)
{
try{return;}
finally{System.out.println("Finally");}
}
}
程序运行结果是:
4.指出下列程序运行的结果
publicclassExample
{
Stringstr=newString("good");
char[]ch={'a','b','c'};
publicstaticvoidmain(Stringargs[])
{
Exampleex=newExample();
ex.change(ex.str,ex.ch);
System.out.print(ex.str+"and");
System.out.print(ex.ch);
}
publicvoidchange(Stringstr,charch[])
{
str="testok";
ch[0]='g';
}
}
程序运行结果是:
5.下列代码哪几行会出错:
1)publicclassModify
2){
3)publicstaticvoidmain(Stringargs[])
4){
5)intI,j,k;
6)I=100;
7)while(I>0)
8){
9)j=I*2;
10)System.out.println("Thevalueofjis"+j);
11)k=k+1;
12)I--;
13)}
14)}
15)}
6.请写出下面程序的运行结果。
publicclassTestextendsTT
{
publicstaticvoidmain(Stringargs[])
{
Testt=newTest("Tom");
}
publicTest(Strings)
{
super(s);
System.out.println("Howdoyoudo?
");
}
publicTest()
{
this("IamTom");
}
}
classTT
{
publicTT()
{
System.out.println("Whatapleasure!
");
}
publicTT(Strings)
{
this();
System.out.println("Iam"+s);
}
}
结果:
7.给定下面的未完成的代码片断:
publicclassExample
{
intx,y;
publicExample(inta)
{
…
x=a;
}
publicExample(inta,intb)
{
//和上面一个参数的构造方法做同样的操作,包括赋值x=a
y=b;
}
}
如果要用最简捷的一行代码实现"//和上面一个参数的…"注释所指出的功能,请写出你认为最合适的一行代码:
8.下列程序中构造了一个SET并且调用其方法add(),输出结果是_______
publicclassA{
publicinthashCode(){return1;}
publicBooleanequals(Objectb){returntrue}
publicstaticvoidmain(Stringargs[])
{Setset=newHashSet();
set.add(newA());
set.add(newA());
set.add(newA());
System.out.println(set.size());
}
}
9.下列程序的运行结果是_______
classA
{classDog
{privateStringname;
privateintage;
publicintstep;
Dog(Strings,inta)
{ name=s;
age=a;
step=0;
}
publicvoidrun(Dogfast)
{fast.step++; }
}
publicstaticvoidmain(Stringargs[])
{Aa=newA();
Dogd=a.newDog("Tom",3);
d.step=25;
d.run(d);
System.out.println(d.step);
}
}
10.Java中类成员的限定词有以下几种:
private,public,,。
其中,的限定的范围最大。
11.Java中所有类都是类的子类。
12.请填出在java.lang包中与下列基本数据类型相对应的封装类:
float:
java.lang.Float,char:
,boolean:
。
13.给定下面的未完成的代码片断:
publicclassExample{
intx,y;
publicExample(inta){
…
x=a;
}
publicExample(inta,intb){
//和上面一个参数的构造方法做同样的操作,包括赋值
x=ay=b;
}
}
如果要用最简捷的一行代码实现"//和上面一个参数的…"注释所指出的功能,请写出你认为最合适的一行代码:
14.如果有一个类MyFrame是Frame的子类,能够被不同包中的类所使用,同时又能够为线程提供运行代码(run()方法),请写出该类的声明头。
你的解答:
三.阅读程序回答问题
⒈下面是JavaAPI类库中System类的定义原型
publicfinalclassjava.lang.Systemextendsjava.lang.Object
{
publicstaticPrintS