我在用K &從SCJP書理解從章面向對象的問題九號B.SCJP面向對象發行
問一個問題:
public class Redwood extends Tree {
public static void main (String [] args) {
new Redwood () . go () ;
}
void go () {
go2 (new Tree () , new Redwood ()) ;
go2 ((Redwood) new Tree () , new Redwood (]
}
void go2 (Tree tl, Redwood rl) {
Redwood r2 = (Redwood) tl;
Tree t2 = (Tree)rl;
}
}
class Tree { }
選項:
What is the result? (Choose all that apply.)
A. An exception is thrown at runtime
B. The code compiles and runs with no output
C. Compilation fails with an error at line 8
D. Compilation fails with an error at line 9
E. Compilation fails with an error at line 12
F. Compilation fails with an error at line 13
書中給出的答案是A,因爲Tre e不能被低估到Redwood。我只是有問題來理解這個概念。
'GO2((紅木)新樹(),新的紅木(]'?錯字? – exexzian