2013 年中兴招聘 Java 开发类笔试题及答案
1.请看以下代码,关于这段代码描述正确的是:( )
public class Account{
private String cardId;
public String getCardId() {
return cardId;
}
public void setCardId (String cardId) {
this. cardId = cardId;
}
}
A.Account 类符合 JavaBean 的规则
B.Account 类不符合 JavaBean 的规则,因为没有无参数构造方法
C.Account 类不符合 JavaBean 的规则,因为没有实现序列化接口
D.Account 类不符合 JavaBean 的规则,因为方法名 getCardId 应改为 getcardId
正确答案:C
2.运行下面程序:
public class Foo {
public static void main(String[] args) {
StringBuffer a=new StringBuffer(“A”);
StringBuffer b=new StringBuffer(“B”);
operator(a,b);
System.out.println(a+”,”+b);
}
public static void operator(StringBuffer x,StringBuffer y){
x.append(y);
y=x;
}
}
输出的结果是:()。
A.A,B
B.A,A
C.B,B
D.AB,B
正确答案:D
3.下面的程序可以输出 1~100 内前 10 个 3 的倍数:
for (int i = 1, count = 0; i < 100; i++) {
if (i % 3 == 0) {
System.out.println(i);
(空白处)
}
}
下列选项中,空白处可以填入的代码是()。
A. if (count++ >= 10) {
break;
}
B. if (++count >= 10) {
break;
}
C. if (count++ >= 10) {
continue;
}
D. if (++count >= 10) {
continue;
}
正确答案:B
4.运行下面程序:
String[] strArr = { “aaa”, “b”, “cc” };
Arrays.sort(strArr, new Comparator() {
public int compare(String o1, String o2) {
return o2.compareTo(o1);
}
});
System.out.println(Arrays.toString(strArr));
输出的结果是:()。
A.[aaa, b, cc]
B.[cc, b, aaa]
C.[b, cc, aaa]
D.[aaa, cc, b]
正确答案:B
5. 对数组 int[] arr = { 52, 93, 16, 67, 36, 92, 26, 12, 25, 92 }用插入排序法由小
到大进行排序,经过 3 轮排序后,数组 arr 的值为:()。
A. {12,16,25,52,93,26,67,36,92,92}
B. {12,16,25,67,36,92,26,52,93,92}
C. {16,52,67,93,36,92,26,12,25,92}
D. {16,36,52,67,93,92,26,12,25,92}
正确答案:C
6.下列代码的输出结果是:()。
public class StaticFoo {
int num;
static int x;
public static void main(String[] args) {
StaticFoo foo1 = new StaticFoo ();
foo1.num++;
foo1.x++;
StaticFoo foo2 = new StaticFoo ();
foo2.num++;
foo2.x++;
StaticFoo foo3 = new StaticFoo ();
foo3.num++;
foo3.x++;
StaticFoo.x++;
System.out.print(foo3.num+”,”);
System.out.println(foo3.x);
}
}
A.3,3
B.1,3
C.3,4
D.1,4
正确答案:D
7.下列代码编译和运行的结果是()
public class Foo {
public static void main(String[] args) {
java.util.List
list = new java.util.ArrayList();
list.add(new B());
list.add(new C());
for (A a : list) {
a.x();
a.y();
}
}
ClassA p4 = new ClassC();
<插入代码>
}
}
可以在<插入代码>处,填入的代码正确的是()
A.p0 = p1;
B.p1 =p2;
C.p2 = p4;
D.p2 = (ClassC)p1;
正确答案:A
9. 运行下面的语句:
System.out.println(Math.round(3.5) + ” ” + Math.floor(3.5) + ” ”
+ Math.ceil(3.5) + ” ” + Math.round(-3.5) + ” ”
+ Math.floor(-3.5) + ” ” + Math.ceil(-3.5));
输出的结果是:()。
A. 4 3.0 4.0 -3 -3.0 -4.0
B. 4 3.0 4.0 -4 -3.0 -4.0
C. 4 4.0 3.0 -4 -4.0 -3.0
D. 4 3.0 4.0 -3 -4.0 -3.0
正确答案:D
10. 下列赋值语句中,正确的是()。
A. byte b1 = 10, b2 = 20;
byte b=b1+b2;
B. byte b1 = 10, b2 = 20;
byte b=~b1;
C. byte b1 = 10, b2 = 20;
byte b=b1>>1;
D. byte b1 = 10;
byte b=++b1;
正确答案:D
11.类 Super 及 Sub 定义如下:
public class Super {
private void f() {
System.out.println(“Super.f()”);
}
public void g() {
f();
}
public void k() {
f();
}
}
public class Sub extends Super {
private void f() {
System.out.println(“Sub.f()”);
}
public void k() {
f();
}
}
运行下列语句:
Super obj = new Sub();
obj.g();
obj.k();
输出的结果是:()。
A. Sub.f()
Sub.f()
B. Sub.f()
Super.f()
C. Super.f()
Sub.f()
D. Super.f()
Super.f()
正确答案:C
12.下列代码的输出结果是()
public static void main(String[] args) {
String test = “a1b2c3″;
String[] tokens = test.split(“\\d”);
for (String s : tokens)
System.out.print(s + ” “);
}
A.a b c
B.1 2 3
C.a1b2c3
D.a1 b2 c3
正确答案:A
13.运行下列程序:
String str = “**java***java*****java*”;
String str1 = “java”;
int index = 0;
while ((index = str.indexOf(str1, index)) != -1) {
System.out.print(index+””);
index += str1.length();
}
控制台输出的结果是:()。
A. 1 8 17
B. 2 9 18
C. 5 12 21
D. 6 13 22
正确答案:B
14.运行下面程序:
public class Foo{
public static void main(String[] args) {
try {
test();
System.out.println(“condition 1″);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(“condition 2″);
} catch (Exception e) {
System.out.println(“condition 3″);