(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
官方答案是A,但是实际编译过程中出现的异常,我真不知道该选什么了。
大家帮助我分析讨论一下。我着急解决这个问题