Java中的继承与现实世界的继承有何不同?(How is inheritance in Java different from real world inheritance?)

编程入门 行业动态 更新时间:2024-10-21 11:44:58
Java中的继承与现实世界的继承有何不同?(How is inheritance in Java different from real world inheritance?)

我在面试中得到了这个问题。 通过现实世界的继承,采访者意味着像泉水一样继承一些财富,父母的某些特征等,

我有一种感觉,这个问题是可以辩论的,并且不会成为一个好的面试问题。

这个问题能够很好地回答吗?

I got this question in an interview. By real world inheritance the interviewer meant things like the off springs inherit some wealth , some characteristics of parents etc.,

I have a feeling that this question is something that can be debated and does not make a good interview question.

Can this question be answered well ?

最满意答案

是的,这个问题可以很好地回答,我认为这是一个很好的面试问题; 如果你能回答这个问题,它表明你理解了面向对象编程的基本概念之一。

面向对象编程中的继承意味着与生物继承完全不同的东西。 OO中的继承意味着专业化 ,意味着一种关系:一个子类的实例是其超类的一种特殊类型的实例。

例如,假设您有class Cat extends Animal 。 猫是一种动物。

有时候,人们在类继承的例子中使用“Parent”和“Child”这两个词,他们将有一个class Parent和一个class Child extends Parent 。 这是错误的:一个孩子不是 (专门的)父母。

Yes, this question can be answered very well and I think it's a good interview question; if you can answer this, it shows that you understand one of the fundamental concepts of object oriented programming.

Inheritance in object oriented programming means something completely different than biological inheritance. Inheritance in OO means specialization and implies an is a relationship: an instance of a subclass is a specialized kind of instance of its superclass.

For example, suppose you have class Cat extends Animal. A Cat is an Animal.

Sometimes people use the words "Parent" and "Child" in examples of class inheritance, where they would have a class Parent and a class Child extends Parent. That's wrong: A Child is not a (specialized kind of) Parent.

更多推荐

本文发布于:2023-08-01 00:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1350569.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有何不同   现实   世界   Java   real

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!