0
Difference between inheritance and polymorphism?
2 Antworten
+ 2
As far as I know, Inheritance allows you to use Base class's features. Polymorphism is a way to call the same method for different objects and generate different results based on the object type.
For example:
You have a base class "Animal" with "move()", "sleep()" and "eat()" methods. Derived classes "Cat" and "Rabbit" inherits "sleep" and "eat" methods, You can use it without redefining, these methods have already defined in base class. That's inheritance.
But "move()" method should be different (running vs jumping). You override it in each derived class, so the same method "move()" generate different results for "Cat" and "Rabbit" class. That's polymorphism.
0
thankyou for answering