本试卷共计40题,每题可能有一个或多个答案。
A. BigOlLongStringWithMeaninglessName
B. $int
C. bytes
D. $1
E. final
F. _666888
Object[] x = new Object[25];
当运行后,下面的哪些说法是正确的?
A. x[24] 为 0。
B. x[2] = new String(“test”); x[3] = new Box(1,2,3);
C. x[25] 为0。
D. x[0] 为null。
E. x.length 为 25。
1. class Q6 {
2. public static void main(String args[]) {
3. Holder h = new Holder();
4. h.held = 100;
5. h.bump(h);
6. System.out.println(h.held);
7. }
8. }
9.
10. class Holder {
11. public int held;
12. public void bump(Holder theHolder) {
theHolder = new Holder();
theHolder.held = 0;
13. theHolder.held++;
14. }
15. }
在第 6行打印的值是:
A. 0
B. 1
C. 100
D. 101
System.out.println(“Equal”);}
B. int x = 100; Integer y = new Integer(100);if (x == y)
{ System.out.println(“Equal”);}
C. Integer x = new Integer(100);byte b = 100;Byte y = new
Byte(b);if (x == y) {
System.out.println(“Equal”);}
D. String x = new String(“100″);String y = new
String(“100″);if (x == y) {
System.out.println(“Equal”);}
E. String x = “100″;String y = “100″;if (x == y) {
System.out.println(“Equal”);}
A. b contains -30
B. b contains 15
C. b contains 245
D. b contains -12
A. 第5行和12行不能编译,因为该方法没有方法名和返回值。
B. 第12 行不能编译,因为只能有一个static初始化块。
C. 代码编译并执行,输出结果x = 10.
D. 代码编译并执行,输出结果 x = 5.
E. 代码编译并执行,输出结果 x = 15.
A. Yes
B. No
题13,14的类层次图:

下面的哪个说法是正确的?
A. 第5行不能编译。
B. 第6行不能编译。
C. 代码编译成功,但是在第6行将抛出异常。
D. 代码编译成功并运行。
E. 代码编译成功并运行,但是第6行的类型转换不需要并可以去掉。
A. i = 0 j = 0
B. i = 0 j = 1
C. i = 0 j = 2
D. i = 1 j = 0
E. i = 1 j = 1
F. i = 1 j = 2
A. 第5行非法。
B. switch()中的j 的类型可以是byte, short, int, long。
C. 输出结果是: value is two.
D. 输出结果是: value is two ,value is three.
E. 输出结果是: value is two, value is three, value is 2.

1. try {
2. // assume s is previously defined
3. URL u = new URL(s); //
4. // in is an ObjectInputStream
5. Object o = in.readObject();
6. System.out.println(“Success”);
7. }
8. catch (MalformedURLException e) {
9. System.out.println(“Bad URL”);
10. }
11. catch (StreamCorruptedException e) {
12. System.out.println(“Bad file contents”);
13. }
14. catch (Exception e) {
15. System.out.println(“General exception”);
16. }
17. finally {
18. System.out.println(“Doing finally part”);
19. }
20. System.out.println(“Carrying on”);
如果第3行的构造函数抛出 MalformedURLException,下面哪些是输出的内容?
A. Success
B. Bad URL
C. Bad file contents
D. General exception
E. Doing finally part
F. Carrying on

1. try {
2. // assume s is previously defined
3. URL u = new URL(s);
4. // in is an ObjectInputStream
5. Object o = in.readObject();
6. System.out.println(“Success”);
7. }
8. catch (MalformedURLException e) {
9. System.out.println(“Bad URL”);
10. }
11. catch (StreamCorruptedException e) {
12. System.out.println(“Bad file contents”);
13. }
14. catch (Exception e) {
15. System.out.println(“General exception”);
16. }
17. finally {
18. System.out.println(“Doing finally part”);
19. }
20. System.out.println(“Carrying on”);
如果第5行的方法抛出异常OutOfMemoryError,下面哪些是输出?
A. Success
B. Bad URL
C. Bad file contents
D. General exception
E. Doing finally part
F. Carrying on
2. throw new IOException(“File ” + f.getName() + “not found”);
3. }
C.
1. if (!f.exists()) {
2. throw IOException;
3. }
D.
1. if (!f.exists()) {
2. throw “File not found”;
3. }
E.
1. if (!f.exists()) { // f is a File object
2. throw new IOException();
3. }
1. public class Test1 {
2. public float aMethod(float a, float b) {
3. }
4.
5. }
如果在第4行单独添加下面的某个方法,那么哪些方法是合法的?
A. public int aMethod(int a, int b) { }
B. public float aMethod(float a, float b) { }
C. public float aMethod(float a, float b, int c) throws Exception{}
D. public float aMethod(float c, float d) { }
E. private float aMethod(int a, int b, int c) { }
1. public class Base {
2. public void method(int i) {
3. System.out.println(“Value is ” + i);
4. }
5. }
1. public class Sub extends Base {
2. public void method(int j) {
3. System.out.println(“This value is ” + j);
4. }
5. public void method(String s) {
6. System.out.println(“I was passed ” + s);
7. }
8. public static void main(String args[]) {
9. Base b1 = new Base();
10. Base b2 = new Sub();
11. b1.method(5);
12. b2.method(6);
13. }
14. }
当运行Sub的main方法,将输出什么?
A. Value is 5 Value is 6
B. This value is 5 This value is 6
C. Value is 5 This value is 6
D. This value is 5 Value is 6
E. I was passed 5 I was passed 6
1. public class Test extends Base {
2. public Test(int j) {
3. }
4. public Test(int j, int k) {
5. super(j, k);
6. }
7. }
下面哪些调用是合法的?
A. Test t = new Test();
B. Test t = new Test(1);
C. Test t = new Test(1, 2);
D. Test t = new Test(1, 2, 3);
E. Test t = (new Base()).new Test(1);
1. public class Test extends Base {
2. public Test(int j) {
3. }
4. public Test(int j, int k) {
5. super(j, k);
6. }
7. }
下面哪个构造函数必须显示地在Base类中定义?假定Test和 Base在同一个包中。
A. Base() { }
B. Base(int j) { }
C. Base(int j, int k) { }
D. Base(int j, int k, int l) { }
1. public class Outer {
2. public int a = 1;
3. private int b = 2;
4. public void method(final int c) {
5. int d = 3;
6. class Inner {
7. private void iMethod(int e) {
8. System.out.println( );
9. }
10. }
11. }
12. }
在第8行哪些变量可以正确地被引用?
A. a
B. b
C. c
D. d
E. e
A. s.append(“aaa”);
B. s = s.trim();
C. s = s.substring(3);
D. s = s.replace(‘z’, ‘a’);
E. s.concat(s);
F. 上面的答案都不正确
1. String s1 = “abc” + “def”;
2. String s2 = new String(s1);
3.String s3 = “abc” + “def”;
4. if (s1 == s3)
5. System.out.println(“== succeeded”);
6. if (s1.equals(s2))
7. System.out.println(“.equals() succeeded”);
A. 第 5 和第7行都执行。
B. 第5 执行,但是第7 行不执行。
C. 第7行执行,但第5行不执行。.
D. 第5行和第7行都不执行。
1. StringBuffer sbuf = new StringBuffer(“abcde”);
2. StringBuffer sbuf2 = sbuf.insert(3, “xyz”);
A. sbuf == sbuf2
B. sbuf != sbuf2
1.运行Java程序时如果用到了其它目录中的类必须指定类路径,或者在环境变量中设置类路径。
2.class文件的类路径由文件所在的目录和文件名组成。
3.class文件的类路径由该类所在的包对应的目录结构的第一层目录的父目录组成。
4.jar文件的类路径由该文件所在的目录和文件名组成。
1. 当一个对象不再有引用变量引用它时,那么垃圾收集器将会回收它。
2. 对象是在内存的堆中分配的。
3. 实例变量在堆中分配,而局部变量在栈中分配。
4. 静态变量在类装载时初始化。
5.
不能对泛型类中的参数类型实例化。
public
class C1 {
public
void test1() {
System.out.println(“C1:test1″);
}
public
void test2() {
System.out.println(“C1:test2″);
}
public
static
void test3() {
System.out.println(“C1:test3″);
}
public
static
void main(String[] args) {
C1 c1 = new C3();
c1.test1();
c1.test2();
c1.test3();
}
}
class C2 extends C1 {
public
void test2() {
System.out.println(“C2:test2″);
}
}
class C3 extends C2 {
public
void test1() {
System.out.println(“C3:test1″);
}
public
static
void test3() {
System.out.println(“C3:test3″);
}
}
A.
C3:test1
C2:test2
C1:test3
B.
C1:test1
C2:test2
C1:test3
C.
C3:test1
C1:test2
C3:test3
D.
C1:test1
C2:test2
C3:test3
E.
C1:test1
C1:test2
C1:test3
public class Value {
public int i = 15;
}
public class Test {
public static void main(String argv[]) {
Test t = new Test();
t.first();
}
public void first() {
int i = 5;
Value v = new Value();
v.i = 25;
second(v, i);
System.out.println(v.i);
}
public void second(Value v, int i) {
i = 0;
v.i = 20;
Value val = new Value();
v = val;
System.out.println(v.i + ” ” + i);
}
}
class MyParent {
int x, y;
MyParent(int x, int y) {
this.x = x;
this.y = y;
}
public int addMe(int x, int y) {
return this.x + x + y + this.y;
}
public int addMe(MyParent myPar) {
return addMe(myPar.x, myPar.y);
}
}
class MyChild extends MyParent {
int z;
MyChild(int x, int y, int z) {
super(x, y);
this.z = z;
}
public int addMe(int x, int y, int z) {
return this.x + x + this.y + y + this.z + z;
}
public int addMe(MyChild myChi) {
return addMe(myChi.x, myChi.y, myChi.z);
}
public int addMe(int x, int y) {
return this.x + x + this.y + y;
}
}
public class MySomeOne {
public static void main(String args[]) {
MyChild myChi = new MyChild(10, 20, 30);
MyParent myPar = new MyParent(10, 20);
int x = myChi.addMe(10, 20, 30);
int y = myChi.addMe(myChi);
int z = myPar.addMe(myPar);
System.out.println(x + y + z);
}
}
public void method1() {
boolean a = true;
boolean b = false;
boolean c = true;
if (a == true)
if (b == true)
if (c == true)
System.out.println(“Some things are true in this world”);
else
System.out.println(“Nothing is true in this world!”);
else if (a && (b = c))
System.out
.println(“It’s too confusing to tell what is true and what is false”);
else
System.out.println(“Hey this won’t compile”);
}
A.The code won’t compile.
B.”some things are true in this world” will be printed
C.”hey this won’t compile” will be printed
D.None of these
A. 枚举既不能是其它类的超类,也不能是其它类的子类。
B. 枚举中的常量是静态的,因此每个枚举常量只实例化一次,实例化时调用枚举中的构造函数。
C.运行时系统和应用程序都可以产生异常。
D. Java虚拟机为每个类型创建唯一的Class对象
E. 方法重载、方法覆盖和接口都实现了java的多态性。
F. 如果要生成内部类实例,那么必须先生成外部类的实例。
A. 32 / 4;
B. (8 >> 2) << 4;
C. 2 ^ 5;
D. 128 >>> 2;
E. (2 << 1) * (32 >> 3);
F. 2 >> 5;
1. class Test {
2. public static void main(String [] args) {
3. int x= 0;
4. int y= 0;
5. for (int z = 0; z < 5; z++) {
6. if (( ++x > 2 ) && (++y > 2)) {
7. x++;
8. }
9. }
10. System.out.println(x + ” ” + y);
11. }
12. }
下面哪些语句插入到9/10行会有编译错误
A. char [] [] c = new char [2][2];
return c;
B. return (Object) 7;
C. return (Object) (new int [] {1,2,3} );
D. ArrayList a = new ArrayList();
return a;
E. return (Object) “test”;
F. return (Float) 4.3;
答案:
1: A B C D F
2: B D E
3: C
4: B C
5: A B E
6: A
7: B C G
8: D
9: D
10: 6 10
11: B
12: D F
13: D
14: B
15: D
16: D
17: B E F
18: E
19: B
20: A C E
21: C
22: B C
23: A C
24: A B C E
25: F
26: A
27: A
28: 1 3 4
29: 1 2 3 4 5
30: A
31: 3
32: 15 0 20
33: 300
34: D
35: A B C D E F
36: B D
37: 6 3
38: 101
39: B D
40: F