| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 553 人关注过本帖
标题:[求助]有答案都不明白什么意思。。。
只看楼主 加入收藏
wxhwjsw
Rank: 1
等 级:新手上路
帖 子:274
专家分:0
注 册:2006-6-15
收藏
 问题点数:0 回复次数:2 
[求助]有答案都不明白什么意思。。。

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
NiceGirl
Rank: 2
等 级:新手上路
威 望:4
帖 子:909
专家分:0
注 册:2006-6-18
收藏
得分:0 
以下是引用wxhwjsw在2006-8-11 17:08:04的发言:

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-08-11 17:34
wxhwjsw
Rank: 1
等 级:新手上路
帖 子:274
专家分:0
注 册:2006-6-15
收藏
得分:0 
哦  明白了 谢  

一个人的快乐,不是因为他拥有的多,而是因为他计较的少.
2006-08-11 17:38
快速回复:[求助]有答案都不明白什么意思。。。
数据加载中...
 
   



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

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