华中科技大学本科《Java语言程序设计》试题闭卷.docx
《华中科技大学本科《Java语言程序设计》试题闭卷.docx》由会员分享,可在线阅读,更多相关《华中科技大学本科《Java语言程序设计》试题闭卷.docx(13页珍藏版)》请在冰豆网上搜索。
华中科技大学本科《Java语言程序设计》试题闭卷
华中科技大学本科《Java语言程序设计》试题·2005(闭卷)
班级:
学号:
姓名:
分数:
一、单项选择题(每小题1分,共20分)
1.下面的变量定义语句,不正确的是:
()
A.Strings姓名="王刚";
B.intfinal=123;
C.doubled_123;
D.charc='王';
2.给定下列代码:
publicclassTest{
intarr[]=newint[2];
publicstaticvoidmain(Stringa[]){
System.out.println(arr[2]);
}
}
上述程序的编译运行结果应该是:
()
A、编译出错
B、编译通过,但运行时产生异常
C、编译通过,运行结果为null
D、编译通过,运行结果为0
3.类MyClass被声明为public类型,其成员字符串变量s只能被自己或同一个包中的其他类访问,满足条件的声明语句为:
矚慫润厲钐瘗睞枥庑赖。
A.privateStrings;
B.publicStrings;
C.protectedStrings;
D.packageStrings;
4.给定下列代码:
classA{
A(inti){
System.out.println("ClassAConstructor"+i);
}
}
publicclassBextendsA{
B(inti){
System.out.println("ClassBConstructor"+i);
}
publicstaticvoidmain(Stringargs[]){
Bb=newB(100);
}
}
上述代码的编译运行结果是:
()
A.ClassBConstructor100
B.ClassAConstructor100
ClassBConstructor100
C.该程序会产生编译错误
D.程序编译通过,但运行时会产生异常并中止
5.关于Java语言中方法的参数传递,正确的描述是:
()
A.方法的参数均是按值传递
B.方法的参数均是按引用传递
C.方法的参数如果是基本类型,则按值传递;否则按引用传递
D.可通过关键字来指定方法的参数是按值传递还是按引用传递
6.将int型变量i的值转换为String类型并赋值给字符串变量s(例如i=10,则s="10"),正确的写法是:
()聞創沟燴鐺險爱氇谴净。
A.s=i.toString();
B.s=Integer(i).toString();
C.s=Integer.valueOf(i);
D.s=String.valueOf(i);
7.如果希望某类中的公有成员变量可在其他类中通过"类名.变量名"进行引用,定义变量时应采用的修饰关键字是:
()残骛楼諍锩瀨濟溆塹籟。
A.static
B.native
C.final
D.finally
8.关于异常处理,下面说法不正确的是:
()
A.从RuntimeException直接或间接继承的异常可以不必捕获
B.如果某方法用throw语句抛出了异常,该方法声明时不一定必须指明throws子句
C.如果将父类异常的catch语句写在子类异常之前,那么程序运行时只会执行父类异常的语句
D.InterruptedException属于须检查的异常
9.如果需要将某个对象通过网络发送到远程系统,应采用那种合适的I/O类?
()
A.PipedReader/PipedWriter
B.PipedInputStream/PipedOutputStream
C.ObjectInputStream/ObjectOutputStream
D.DataInputStream/DataOutputStream
10.给定下列代码:
publicclassThreadTestextendsThread{
publicvoidrun(){
System.out.println("Inrun");
yield();
System.out.println("Leavingrun");
}
publicstaticvoidmain(Stringargs[]){
(newThreadTest()).start();
}
}
上述程序编译运行的结果是:
()
A.Inrun
B.Leavingrun
C.Inrun
Leavingrun
D.程序正常运行,但什么都不显示
11、System类存在于下列哪一个包中?
()
A.java.lang
B.java.io
C.java.util
D.未定义包
12、关于System.out.println();语句,说法正确的是:
A.out是System类的一个静态属性
B.out是System类的一个静态方法
C.println是System类的一个静态方法
D.println是System类的一个非静态方法
13、定义一个不允许被其它类所继承的类,可使用的类修饰符是:
A.static
B.final
C.protected
D.abstract
14、类A继承了类B,并实现了接口C,以下类的声明语句正确的是:
A.classAextendsBimplementsC
B.classAextendsCimplementsB
C.classBextendsAimplementsC
D.classBextendsCimplementsA
15、定义一个无返回值的抽象方法,以下语句正确的是:
A.abstractvoidtest(){}
B.abstractvoidtest();
C.voidabstracttest(){}
D.voidabstracttest();
16、类C的定义如下:
classCextendsBimplementsA{
…
}
下列表达式中,不正确的是:
()
A.Cc=newC();
B.Bb=newC();
C.Aa=newC();
D.Cc=newB();
17、希望按"东南西北中"的方位安排组件的摆放,容器应该采用那种布局类?
()
A.FlowLayoutB.BorderLayoutC.CardLayoutD.GridLayout酽锕极額閉镇桧猪訣锥。
18、下列不是Java引用类型的是:
()
A.int[]
B.Object
C.Runnable
D.char
19.给定下列代码:
classTest{
publicstaticvoidmain(String[]args){
Floats=newFloat(0.9F);
Floatt=newFloat(0.9F);
Doubleu=newDouble(0.9);
System.out.println(s==t);
System.out.println(s.equals(t));
System.out.println(t.equals(u));
}
}
上述程序的运行结果是:
()
A.true
true
true
B.false
true
true
C.false
true
false
D.false
false
false
20、给定下列代码:
classBase{
intx=2;
intmethod(){
returnx;
}
}
classSubclassextendsBase{
intx=3;
intmethod(){
returnx;
}
}
classTest{
publicstaticvoidmain(String[]args){
Baseb=newSubclass();
System.out.println(b.x);
System.out.println(b.method());
}
}
上述代码的运行结果是:
()
A.23
B.22
C.33
D.32
E.以上都不对,因为Baseb=newSubclass()是非法语句
二、根据程序回答问题(共65分)
1、写出下列程序的运行结果(共20分)
(1)程序:
(6分)
classC{
C(){
System.out.print("C");
}
}
classA{
Cc=newC();
A(){
this("A");
System.out.print("A");
}
A(Strings){
System.out.print(s);
}
}
classBextendsA{
B(){
super("B");
System.out.print("B");
}
publicstaticvoidmain(String[]args){
newB();
}
}
运行结果:
(2)程序:
(8分)
PublicclassNote{
publicstaticvoidswap(Stringname[]){
Stringtemp;
temp=name[0];
name[0]=name[1];
name[1]=temp;
}
publicstaticvoidswap(Stringname0,Stringname1){
Stringtemp;
temp=name0;
name0=name1;
name1=temp;
}
publicstaticvoidmain(Stringargs[]){
Stringname[]={"Killer","Miller"};
Stringname0="Killer";
Stringname1="Miller";
swap(name0,name1);
System.out.println(name0+","+name1);
swap(name);
System.out.println(name[0]+","+name[1]);
}
}
运行结果:
(3)程序:
(6分)
classUnchecked{
staticvoidmethod(){
try{
wrench();
System.out.print("a");
}catch(ArithmeticExceptione){
System.out.print("b");
}finally{
System.out.print("c");
}
System.out.print("d");
}
staticvoidwrench(){
thrownewNullPointerException();
}
publicstaticvoidmain(String[]args){
try{
method();
}catch(Exceptione){
System.out.print("e");
}
System.out.print("f");
}
}
运行结果:
2、根据程序回答问题(共10分)
publicclassJLab0603{
publicstaticvoidchange(Strings){
s=s+"changed?
";
}
publicstaticvoidchange(StringBuffersb){
sb.append("changed?
");
}
publicstaticvoidmain(String[]args){
Strings="test";
StringBuffersb=newStringBuffer("test");
System.out.println("s="+s+",sb="+sb);
change(s);
change(sb);
System.out.println("s="+s+",sb="+sb);
}
}
(1)该程序的运行结果是:
(4分)
(2)用简洁明了的语言说明为什么会产生这样的结果?
(6分)
3、根据程序运行结果填空(共15分)
注意:
一个空格处只能填写一条语句
classGate{
publicvoidwaitAtGate(){
try{
}catch(InterruptedExceptione){}
}
publicvoidnotifyAllAtGate(){
}
}
classTangledThread{
Gategate;
publicTangledThread(Stringstr,Gateg){
}
publicvoid{
try{sleep((int)(Math.random()*100));}
catch(InterruptedExceptione){}
System.out.print("..."+getName()+"...");
}
}
classLooseThread{
Gategate;
publicLooseThread(Stringstr,Gateg){
}
publicvoid{
System.out.print("..."+getName()+"...");
}
}
publicclassThreadProblem{
publicstaticvoidmain(String[]args){
newTangledThread("Study",g).start();
newTangledThread("Party",g).start();
newLooseThread("Sleep",g).start();
}
}
该程序所有可能的运行结果为: