标题:[求助]有答案都不明白什么意思。。。
取消只看楼主
wxhwjsw
Rank: 1
等 级:新手上路
帖 子:274
专家分:0
注 册:2006-6-15
 问题点数:0 回复次数:1 
[求助]有答案都不明白什么意思。。。

We have the following organization of classes.

class Parent { }
class DerivedOne extends Parent { }
class DerivedTwo extends Parent { }

Which of the following statements is correct for the following expression?

Parent p = new Parent();
DerivedOne d1 = new DerivedOne();
DerivedTwo d2 = new DerivedTwo();
d1 = (DerivedOne)d2;

Illegal both compile and runtime
Legal at compile time, but fails at runtime
Legal at compile and runtime
None of the above
给出的答案是A,他的解释如下:
解释是
A is correct. You cannot assign an object to a sibling(no parent-child relation) reference, even with casting.
还请高手指教下。。。。

[此贴子已经被作者于2006-8-11 17:11:24编辑过]

搜索更多相关主题的帖子: expression statements following classes correct 
2006-08-11 17:08
wxhwjsw
Rank: 1
等 级:新手上路
帖 子:274
专家分:0
注 册:2006-6-15
得分:0 
哦  明白了 谢  

一个人的快乐,不是因为他拥有的多,而是因为他计较的少.
2006-08-11 17:38



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-83452-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.510908 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved