How is inheritance in Java different from real-world inheritance?
I got this question in an interview Through the inheritance of the real world, the interviewer means that something like spring water inherits some wealth, some characteristics of parents, etc,
I have a feeling that this question can be debated and has not become a good interview question
Can this question be well answered?
Solution
Yes, this question can be well answered. I think it's a good interview question; If you can answer this question, it shows that you understand one of the basic concepts of object - oriented programming
Inheritance in object - oriented programming means something completely different from biological inheritance Inheritance in OO means specialization and implies a relationship: an instance of a subclass is an instance of a special type of its superclass
For example, suppose you have the cat extensions animal class Cats are animals
Sometimes people use the words "parent" and "child" in the example of class inheritance, where they will have a class parent and a child extended parent That's wrong: children are not (special) parents