Pratik Bhoir Pratik Bhoir - 2 months ago 9
C# Question

Difference between Class Inherit, extend and implement oops

I know this is a stupid question, but still want to know it clearly.
The proper difference between
Inheriting a class,
extending a class,
Implementing a class

Please explain with examples.

And if you can provide me a source for a complete detailed oops in c# for studying.
Thanks in advance.

Answer

To clarify what Feisty Mango commented:

Inheriting refers to the relationship between a derived class (the child) and the base class (the parent). The derived class can use certain methods and fields within the base class according to accessibility levels (more about that here)

Extending is interchangeable with Inheriting and usually is used in java (since the syntax for inheritance in java is the keyword extends. In C#, it is colon :

Implementing usually is used with interfaces instead of classes. Mainly because inheriting or extending implies parts of classes are being consumed, where with implementing, it implies the entire interface must be defined by whoever implements it.

Another thing to keep in mind is that you can only extend or inherit one class in C#, but can implement multiple interfaces!

MSDN provides good information related to inheritance, among other places