1、 一、选择题(每小题2分,共60分) 得 分 阅 卷 1.Java语言是1995年由( )公司发布的。 A. Sun B. Microsoft C. Borland D. Fox Software 2.下列声明和赋值语句错误的是( ) A. double w=3.1415; B. String strl="bye"; C. float z=6.74567; D. boolean truth=true; 3. paint()方法使用哪种类型的参数? A. Graphics B. Graphics2D
2、 C. String D. Color 4. 欲构造ArrayList类的一个实例,此类继承了List接口,下列哪个方法是正确的?( ) A.ArrayList myList=new Object(); B.List myList=new ArrayList(); C. ArrayList myList=new List(); D. List myList=new List(); 5. 指出下列程序运行的结果 public class Example { String str=new String("good"); char[] ch={
3、'a','b','c'}; public static void main(String args[]){ Example ex=new Example(); ex.change(ex.str,ex.ch); System.out.print(ex.str+" and "); System.out.print(ex.ch); } public void change(String str,char ch[]){ str="test ok"; ch[0]='g'; }
4、 } A.good and abc B.good and gbc C.test ok and abc D.test ok and gbc 6. 运行下列程序, 会产生什么结果 1)public class X extends Thread implements Runable{ 2) public void run(){ 3) System.out.println("this is run()"); 4) } 5) public static void main(String args[]){ 6) Thread t=new Thread(new X()
5、); 7) t.start(); 8) } 9)} A.第一行会产生编译错误 B.第六行会产生编译错误 C.第六行会产生运行错误 D.程序会运行和启动 7. 编译、运行下列Java代码后的结果是( )。 public class Test{ public static void main(String args []){ int age; age=age+1; System.out.println("The age is"+age); } } A.编译成功,运行后没有输出 B.编译成功,运行后输出:The age is 1
6、 C.编译成功,但运行时产生错误 D.编译失败 8. 下列程序片断的执行,说法正确的是( ) 1)public class Test{ 2) public static void main(String args[]){ 3) byte b=100; 4) int i=b; 5) int a=2000; 6) b=a; 7) System.out.println(b); 8) } 9)} A. b的值为100 B. b的值为2000 C. 第4行出错 D. 第6行出错 9. 已知i为整型变量,关于一元运算++i
7、和i++,下列说法正确的是( ) A. 在任何情况下变量i的值都增1 B. 在任何情况下运行程序结果都一样 C. 在任何情况下运行程序结果都不一样 D. ++i运算将出错 10.下列方法method()执行,返回值为( ) int method(){ int num=10; if (num>20) return num; num=0; } A. 10 B. 20 C. 30 D. 编译出错 11.下面程序定义了一个类,关于该类说法正确的是( ) abstra
8、ct class abstractClass{ … } A. 该类能调用new abstractClass(),方法实例化为一个对象。 B. 该类不能被继承。 C. 该类的方法都不能被重载。 D. 以上说法都不对。 12.与Applet生命周期有关的主要方法是( ) A.init() B.start() C.stop() D.以上都是 13.使用”java MultiCatch”命令运行下列程序,说法正确的是( ) 1)public class MultiCatch{ 2) public static void main(String args
9、[]){ 3) try{ 4) int a=args.length; 5) int b=42/a; 6) int c[]={1}; 7) c[42]=99; 8) System.out.println("b="+b); 9) } 10) catch(ArithmeticException e){ 11) System.out.println("除0异常:"+e); 12) } 13) catch(ArrayIndexOutOfBoundsException e){ 14) System
10、out.println("数组超越边界异常:"+e); 15) } 16) } 17)} A. 程序将输出第11行的异常信息 B. 程序第7行出错 C. 程序将输出"b=42 " D. 程序将输出第11和14行的异常信息 14.框架(Frame)的缺省布局管理器是( ) A.流程布局(FlowLayout) B.卡式布局(CardLayout) C.边界布局(BorderLayout) D.网格布局(GridLayout) 15.线程调用了sleep()方法后,该线程将进入( )状态。 A.可运行状态 B.运行状态 C.阻塞状态
11、 D.死亡状态 16.JDBC中要显式地关闭数据库连接使用的方法是( ) A.Connection.close(); B.RecordSet.close(); C.Connection.stop(); D.Connection.release(); 17. 以下说法正确的是:( ) A.java.lang包被隐式包含到所有程序中。 B.Java的import关键字用来通知编译器当前正在编写一个数据输入类。 C."import java.awt.*"表示使用一个java.awt包中名称为"*"的类。 D包中包含了java.a
12、wt包 18.下面对类的声明哪个是正确的?( ) A. public class Fred{ public int x = 0; public Fred (int x){ this.x = x; } } B. public class Fred { public int x = 0; public fred (int x){ this.x = x; } } C)public class Fred extends MyBaseClass, MyOtherBaseClass { public int x = 0;
13、 public Fred (int xval){ x = xval; } } D)protected class Fred{ private int x = 0; private Fred (int xval){ x = xval; } } 19. 下面程序中类ClassDemo中定义了一个静态变量sum,程序的输出结果是( )。 class ClassDemo { public static int sum=1; public ClassDemo(){ sum=sum+5;
14、} } class ClassDemoTest{ public static void main(String args[]) { ClassDemo demo1=new ClassDemo(); ClassDemo demo2=new ClassDemo(); System.out.println(demo1.sum); } } A. 0 B. 6 C. 11 D. 2 20. 以下语句不能通过编译的是( )。 A. int[] a={1
15、2,3,4}; B. int b[]; C. int c[]=new int[3]; D. int d=new int[]; 21. 阅读下面程序,程序的运行结果下面说法正确的是( ) class Super{ public int i=0; public Super(String text){ i=1; } } public class Sub extends Super{ public Sub(String text){ super(text); i=2; } public static void main(String arg[]){ Sub
16、 sub=new Sub("Hello"); System.out.println(sub.i); } } A. 编译失败 B.编译成功并且程序输出0 C. 编译成功并且程序输出1 D.编译成功并且程序输出2 22. 在编译下列代码时,什么情况可能会发生?( ) public class MyClass{ public static void main(String arguments[]){ amethod(arguments); } public void amethod(String[] arguments){ System.out
17、println(arguments); System.out.println(arguments[1]); } } A.出错,不能从静态上下文中引用非静态方法amethod() B.出错,main()方法不正确 C.出错,数组应该包含参数 D.出错,amethod()方法必须定义为String类型 23.类Test1定义如下: 1)public class Test1{ 2) public float aMethod(float a, float b){} 3) 4)} 将以下哪种方法插入第3行是不合法的。(
18、 ) A.public float aMethod(float a, float b, float c){ } B.public int aMethod(float c, float d){ } C.public int aMethod(int a, int b){ } D.private float aMethod(int a, int b, int c){ } 24.下面哪个是除零异常( ) A.NullpointerException B.ArithmeticException C.ArrayOutofBoundsException D
19、.SecurityException 25.类的包可见性,一个类只能被自己包内的类访问,类前面加什么修饰符( ) A.缺省的,即没有访问控制符 B.protected C.public D.private 26.下面程序执行结果为( ) public class test implements Runnable{ private int x=4; private int y=5; public static void main(String args[]){ test x=new test(); (new Thread(
20、x)).start(); (new Thread(x)).start(); } public void run(){ x++; y++; System.out.println("x="+x+",y="+y); } } A. x=4,y=5 x=4,y=5 B. x=4,y=5 C. x=4,y=5 x=5,y=6 D.x=5,y=6 x=6,y=7 27.如果要将test.java文件放到名为test的包中,以下声明中正确的是( ) A.package test; class test{} B.class test.
21、test{} C.public package test; class test{} D.以上都不对; 28.下面程序编译执行的结果是( ) public class xx { public void test(int i){ System.out.println("it is a int"); } public static void main(String args[]){ xx x=new xx(); x.test('y'); } } A.不能编译 B.输出结果”it is a int” C.能编译,但不能运行 D. 以上都不对 29.设
22、类B是类C的父类,下列声明对象x1的语句中不正确的是( )。 A.B x1=new B(); B.B x1=new C(); C.C x1=new C(); D.C x1=new B(); 30.下列语句序列执行后,r的值是( )。 int x=5,y=10,r=5; switch(x+y) { case 15: r+=x; case 20: r-=y; case 25: r*=x/y; default: r+=r; } A.15
23、 B.10 C.0 D.20 二、填空题(每空2分,共40分) 得 分 阅 卷 1、下面程序的输出结果是: public class ArrayTest { public static void main (String[] args) { String[] sa = { "Green", "Blue", "Red" }; System.out.println("Color = " + sa[1]); } } 2
24、线程体run()方法是在 接口中定义的。 3、Java系统运行时,通过______机制周期性的释放无用对象所使用的内存,完成对象的清除。 4、Java源文件中最多只能有一个_____类,其它类的个数不限。 5、下列程序输出结果为_______。 public class Test{ public static void main(String args[]){ String s="I am a string!"; int n=s.length(); char c=s.charAt(7); System.out.println(n); Sys
25、tem.out.print(","); System.out.println(c); } } 6、抽象方法只能存在于抽象类中,抽象方法用关键字________来修饰。 7、Throwable类有两个子类:__________类和Exception类。 8、下面程序的运行结果为 public class IfTest{ public static void main(String args[]){ int x=3; int y=1; if(x!=y) System.out.println("Not
26、 equal");
else
System.out.println("Equal");
}
}
9、若有定义int a=2,则执行完语句a-=a*a;后,a的值是 。
10、下列程序段执行后,t3的结果是 。
int t1=4,t2=3,t3;
t3=t1
27、 。 public class Sub{ public static void main(String[] args){ int i=Integer.parseInt(args[0]); switch(i){ case 1: System.out.println("First season"); break; case 2: System.out.println("Second season"); break; case 3: System.out.println("3th season"); break; case 4: System.out.p
28、rintln("Last season"); break; } } } 13、根据下面的程序段,写出程序运行的输出结果: 。 import java.util.Arrays; public class SortArray { public static void main(String args[]) { String[] str = {"size", "abs","length","class"}; Arrays.sort(str); for
29、int i=0; i 30、
do{
System.out.println("printing i="+i);
}while(i-->0);
System.out.println("Finished");
}
}
16、定义字符串:String s1="hello"; 下面的程序段输出的结果是: 。
if (s1.equals("hello"))
System.out.println("s1 equals \"hello\"");
else
System.out.println("s1 does not equals \"hello\"") 31、
17、分析下面程序的输出结果是: 。
public class Example{
public static void main(String[] ards) throws Exception{
try{
throw new Exception();
}catch(Exception e){
System.out.println("Caught Exception!");
}
System.out.println("continue!");
}
}
18、请将下 32、列程序划线部分补充完整。
_______ class C{
abstract void callme();
void metoo(){
System.out.println("类C的metoo()方法");
}
}
class D _______ C{
void callme(){
System.out.println("覆盖类C的callme()方法");
}
}
public class Example{
public static void main(String args[]){
C c=_______ 33、D();
c.callme();
c.metoo();
}
}
(JAVA)理论考试试卷答案
一、选择题(每小题2分,共60分)
1. A
2. C
3. A
4. B
5. B
6. A
7. D
8. D
9. A
10. D
11. D
12. D
13. A
14. C
15. C
16. A
17. A
18. A
19. C
20. D
21. D
22. A
23. B
24. B
25. A
26. D
27. A
28. B
29. D
30. C
34、
二、填空题(每小题2分,共40分)
1. Color = Blue
2. Runnable
3. 垃圾回收
4. public或公共
5. 14,s
6. abstract
7. Error
8. Not equal
9. -2
10. 7
11. 12
12. 3th season
13. abs_class_length_size_
14. 3
15. printing i=1
printing i=0
Finished
16. s1 equals "hello"
17. Caught Exception!
continue!
18. abstract extends new
第 12 页 共 12 页






