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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Smart LuckyPosted Nov 28, 2014, 5:19 AM
MahaPosted Nov 28, 2014, 5:15 AM
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.
Kyle StoryPosted Nov 28, 2014, 4:14 AM
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.