Hi dudes
Can any one tell me
What is the difference between class inheritance and interface inheritance (orsubtyping) means interface implementation in C#.
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Kyle Story24 reputationPosted Nov 27, 2014, 11:14 PM EST
You are inheriting a certain class because you get all its public, protected and internal goodies (members, methods, etc.). So that is why the word inheritance is used here, you are inheriting the behaviours from your base class.
You are not inheriting an interface, you are implementing it. The difference is that interface defines a contract, aka what that class needs to have when it is declaring that it comes from me, here 'me' refers to a specific interface.
I probably have a bit bad explanation skills, but the point is that word inheritance is used because the behaviours already exist and thus you are just taking them as they are (of course you can modify them but that is beside the point now).
While on the other hand the word implementation is used because the behaviour does not exist, only its signature (how the method or the property needs to look) exists and you need to implement the logic by yourself.
MahaRank #2,573 · 543 reputationPosted Nov 28, 2014, 12:15 AM EST
One parent class can have many child classes inherited from its parent class. But C# will not allow a child class to inherit from many parent classes. Because one child can't have many parents, this is a real world scenario.
In other words multiple inheritances are not allowed in C#. In order to fulfill such a need Interfaces are used.
Smart LuckyRank #2,625 · 531 reputationPosted Nov 28, 2014, 12:19 AM EST