Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 224
user2434 Avatar asked Dec 05 '25 22:12

user2434


1 Answers

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.

like image 62
Jesper Avatar answered Dec 07 '25 13:12

Jesper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!