An immutable class cannot have _______.
C
单选题 (1 分) 1 分
A.
static data fields
B.
no-arg constructors
C.
public data fields
D.
public constructors
E.
private data fields
2.
A source code file may contain several classes.
A
判断题 (1 分) 1 分
A.
true
B.
false
4.
You can declare variables of the same name in a method even though they are in the same block.
B
判断题 (1 分) 0 分
A.
true
B.
false
5.
All data fields in an object have default values(默认值).
A
判断题 (1 分) 1 分
A.
true
B.
false
6.
What is the printout of the second println statement in the main method?
public class Foo {
int i;
static int s;
public static void main(String[] args) {
Foo f1 = new Foo();
System.out.println("f1.i is " + f1.i + " f1.s is " + f1.s);
Foo f2 = new Foo();
System.out.println("f2.i is " + f2.i + " f2.s is " + f2.s);
Foo f3 = new Foo();
System.out.println("f3.i is " + f3.i + " f3.s is " + f3.s);
}
public Foo() {
i++;
s++;
}
}
D
单选题 (1 分) 0 分
A.
f2.i is 2 f2.s is 1
B.
f2.i is 2 f2.s is 2
C.
f2.i is 1 f2.s is 1
D.
f2.i is 1 f2.s is 2
9.You can declare variables of the same name in a method if they are in non-nesting blocks.
判断题 (1 分)
B
A.false
B.true
10.
What is the value of times displayed?
public class Test {
public static void main(String[] args) {
Count myCount = new Count();
int times = 0;
for (int i=0; i<100; i++)
increment(myCount, times);
System.out.println(
"myCount.count = " + myCount.count);
System.out.println("times = "+ times);
}
public static void increment(Count c, int times) {
c.count++;
times++;
}
}
class Count {
int count;
Count(int c) {
count = c;
}
Count() {
count = 1;
}
}
单选题 (1 分)
D
A.98
B.99
C.100
D.0
E.101
12.
Analyze the following code:
public class Test {
private int t;
public static void main(String[] args) {
int x;
System.out.println(t);
}
}
单选题 (1 分)
A
A.t is non-static and it cannot be referenced in a static context in the main method.
B.The program compiles and runs fine.
C.The variable x is not initialized and therefore causes errors.
D.The variable t is not initialized and therefore causes errors.
E.The variable t is private and therefore cannot be accessed in the main method.
13.Which of the following statements are true?
多选题 (2 分)
ABCD
A.Constructors(构造函数) must have the same name as the class itself.
B.Constructors are invoked using the new operator when an object is created.
C.Constructors do not have a return type, not even void.
D.Multiple constructors can be defined in a class.
14.
Analyze the following code:
public class Test {
public static void main(String[] args) {
double radius;
final double PI= 3.15169;
double area = radius * radius * PI;
System.out.println("Area is " + area);
}
}
单选题 (1 分)
A
A.The program has compile(编译) errors because the variable radius i