Section A
(1)
1.public class Test {
2.public static void main(String arg[]){
3.class Foo{
4.public int i = 3;
5.}
6.Object o = (Object)new Foo();
7.Foo foo = (Foo)o;
8.System.out.println(" i = " + foo.i);
9.}
10.}
What is the result?
A. i = 3
B. Compilation fails. 编译错误
C. A ClassCastException is thrown at line 6. 第6行抛出异常
D. A ClassCastException is thrown at line 7. 第7行抛出异常
Answer:A
将Foo对象向上塑形为object(on line 6),然后又把Foo向下塑形为Foo(on line 7),最后访问打印Foo中的public属性i.打印出i=3.
(2)
Which two cause a complier error?(Choose two)
哪两个可以引起编译器出错?
A. float[] = new float(3);
B. float f2[] = new float[];
C. float[] f1 = new float[3];
D. float f3[] = new float[3];
E. float f5[] = {1.0f, 2.0f, 2.0f};
F. float f4[] = new float[] {1.0f. 2.0f. 3.0f};
官方答案Answer:A,B
The F.statement is incorrect. The float numbers should be separated with commas and not dots.
F也是错误的。浮点数应该用","隔开而不是"."。
A答案没有变量。B答案没有指定数组维数。
(3)
int i = 1, j = 10;
do{
if(i++ > --j){
continue;
}
} while(i < 5);
System.out.println("i = " + i + " and j =" + j);
What is the result?
结果是什么?
A. i = 6 and j = 5
B. i = 5 and j = 5
C. i = 6 and j = 5
D. i = 5 and j = 6
E. i = 6 and j = 6
Answer: D
程序循环的经典问题,首先由if(i++ > --j){continue;}来看循环应该会无限的执行下去,但while(i < 5)限制了它的执行次数,再由i=1来看,循环执行执行了4次,所以i=1+4=5,j=10-4=6. D答案正确.
(4)
1. class text {
2. private Demo d;
3. void start() {
4. d =
(1)
1.public class Test {
2.public static void main(String arg[]){
3.class Foo{
4.public int i = 3;
5.}
6.Object o = (Object)new Foo();
7.Foo foo = (Foo)o;
8.System.out.println(" i = " + foo.i);
9.}
10.}
What is the result?
A. i = 3
B. Compilation fails. 编译错误
C. A ClassCastException is thrown at line 6. 第6行抛出异常
D. A ClassCastException is thrown at line 7. 第7行抛出异常
Answer:A
将Foo对象向上塑形为object(on line 6),然后又把Foo向下塑形为Foo(on line 7),最后访问打印Foo中的public属性i.打印出i=3.
(2)
Which two cause a complier error?(Choose two)
哪两个可以引起编译器出错?
A. float[] = new float(3);
B. float f2[] = new float[];
C. float[] f1 = new float[3];
D. float f3[] = new float[3];
E. float f5[] = {1.0f, 2.0f, 2.0f};
F. float f4[] = new float[] {1.0f. 2.0f. 3.0f};
官方答案Answer:A,B
The F.statement is incorrect. The float numbers should be separated with commas and not dots.
F也是错误的。浮点数应该用","隔开而不是"."。
A答案没有变量。B答案没有指定数组维数。
(3)
int i = 1, j = 10;
do{
if(i++ > --j){
continue;
}
} while(i < 5);
System.out.println("i = " + i + " and j =" + j);
What is the result?
结果是什么?
A. i = 6 and j = 5
B. i = 5 and j = 5
C. i = 6 and j = 5
D. i = 5 and j = 6
E. i = 6 and j = 6
Answer: D
程序循环的经典问题,首先由if(i++ > --j){continue;}来看循环应该会无限的执行下去,但while(i < 5)限制了它的执行次数,再由i=1来看,循环执行执行了4次,所以i=1+4=5,j=10-4=6. D答案正确.
(4)
1. class text {
2. private Demo d;
3. void start() {
4. d =