C
C#2w ago
Faker

✅ Difference between OOP concept, inheritance vs polymorphism

Hello, at first, for me, both inheritance and polymorphism mean the same thing but by doing some further reading, can someone just confirm whether the following is correct please: From what I've reasd, inheritance is just when we create a class (derived class) that is derived from a base class, "inheriting" methods and fields from the base class. We are creating the "is a" relationship. On the other hand, polymorphism is just when we have objects from multiple classes and making them act as if they were from the same class (the base class). Based on the underlying reference type, the right method is called at run-time.
2 Replies
Jimmacle
Jimmacle2w ago
yes, basically inheritance is how you implement polymorphism in C#
Angius
Angius2w ago
Also, there's, like, 6 or so different types of polymorphism, and not all of them need inheritance

Did you find this page helpful?