一、单项选择题(每小题4分,共40分)
1、以下程序的运行结果为( D )
class Tester{
public static void main(String[] args){
int x = 12, y = 13;
System.out.println(x + " + " + y + " = " + x + y);
}
}
A. x + y = 25 B. 12 + 13 = 25 C. x + y = 1213 D. 12 + 13 = 1213
2、以下程序的运行结果为( B )
public class TestClass{
public static void main(String[] args){
int a = 1;
switch (a) {
case 1: a += 1;
case 2: a +=2; break;
case 3: a += 3;
default: a = 0;
}
System.out.println(a);
}
}
A. 2 B. 4 C. 7 D. 0
(4分)3、以下程序的运行结果为: B
public class Tester{
public static void main(String args[]) {
int count = 1 ;
int[] value= new int[2];
value[0] = 1;
testMethod(count, value);
System.out.println(count + "; " + value[0]);
}
public static void testMethod(int count, int[] value) {
count = count + 2;
value[0] = value[0] + 2;
}
}
A. 1; 1 B. 1; 3 C. 3; 1 D. 3; 3
4、以下程序的运行结果为( C )
public class Tester{
public static int add(int x){
if (x > 0)
return x + add(x - 2);
return x;
}
public static void main(String[] args){
System.out.println(add(5));
}
}
A. 0 B. 1 C. 8 D. 以上都不对
5、设类Car是类Vehicle的派生类,car, vehicle分别是类Car与Vehicle的对象,以下语句存在语法错误的是(A )
A. car = new Vehicle(); B. vehicle = new Car(); C. car = (Car) vehicle; D. vehicle = car;
6、以下关于Java继承与接口的描述中,正确的是( B )
A. 支持多继承与多接口实现 B. 支持单一继承与多接口实现
C. 支持单一继承与单一接口实现 D. 支持多继承与单一接口实现
7、设value为一个四位整数(如1234),以下代码能够获得其百位上数值(应为2)的是(A )
A. value / 100 % 10; B. value % 100 / 10; C. value / 10 % 100; C. value % 10 / 100;
8、以下能够为value随机赋予[10, 100)之间的整数值的是(A)
A. value = (int) (Math.random() * 90) + 10; B. value = (int) (Math.random() * 100) - 10;
A. value = (int) (Math.random() * 10) + 90; D. 以上都不对
9、以下表达式可以用于判断某年(用year表示)是否是润年(表达式值为true表示是润年,否则不是润年)的是(B )
A. (year % 4 == 0) && ((year % 100 != 0) || year % 400 == 0)
B. (year % 4 == 0) && (year % 100 != 0) || year % 400 == 0
C. (year / 4 == 0) && ((year / 100 != 0) || year / 400 == 0)
D. (year / 4 == 0) && (year / 100 != 0) || year / 400 == 0
10、以下程序的运行结果为( D )
class Tester{
static int a = 1;
public static void main() {
for (int i = 0;i < 3; i ++) fun();
System.ou