派生类和基类 [英] a deriver Class and base Class

查看:79
本文介绍了派生类和基类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

派生类通常比其基类更大且更通用。





这是真的

我解决了它我是对还是错?!!

A Derived Class is often larger than and more general than its base class.


This True of False
I Solved It False Am I right or not ?!!

推荐答案

假基类是父级而且更通用。



你是对的,但下次,请添加你为什么这么认为的理由。
False as base class is parent and more general.

You were right, but next time, do add the reason on why you think so.


这是完全错误的题。它有两个不同且不相关的陈述。派生类通常更大,这是真的(通常,但不总是,只在某种意义上,请见下文),但通常不是更一般,但恰恰相反,更专业。它无法用真或假来回答。



所以,正确答案是:问题没有意义,原因如上所述。



更确切地说:没有为类定义更大的关系。当我在上面说更大时,我的意思是:如果你创建了基类的实例和派生类的实例,那么通常第一个占用更少的内存;然而,设计样本的事情恰恰相反,这很容易。此语句基于一个简单的事实,即派生类具有基类的所有成员,可能还有其他内容。但!使用更少的成员,您可以获得更多的内存,而不是更多的成员。例如,您可以在基类中初始化一个长字符串,使其在派生类中缩短,但添加更多成员。然后基类更大。你可以用普通英语发明一些关于更大关系的其他含义。这并不意味着它有严格的意义。提出这样的问题只是不诚实。



我怀疑这是面试问题。我也怀疑它是由非常纯粹理解本质事物的人发明的。再次!如果你去采访,不幸的是你面临太多的白痴。



-SA
This is a totally incorrect question. It has two different and unrelated statement in it. The derived class it usually larger, that''s true (only usually, not always, and only in certain sense, please see below), but normally not more general, but just the opposite, more specialized. It cannot be answered by one true or false.

So, correct answer is: the question makes no sense, by the reason explained above.

To be more precise: a relationship "larger" is not defined for classes. When I said "larger" above, I rather meant: if you create instance of the base class and instance of the derived class, it''s pretty usual that the first one takes less memory; however, it''s easy to design the sample where things are the opposite. This statement is based on simple fact that the derived class has all members of the base class and possibly something else. But! with less number of members you can get more memory than with more members. For example, you can initialize a long string in base class, make it much shorted in derived class but add more members. Then base class is larger. You can invent some other meanings of the relationship "larger", based in common English. It does not mean it has strict sense. Asking such questions is just dishonest.

I suspect this is the interview question. I also suspect it is invented by people who very purely understand the essence things. Again! If you go for interviews, you face too many morons, unfortunately.

—SA


这篇关于派生类和基类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆