Difference between Class Inherit, extend and implement oops
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.
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!
Microsoft Docs provides good information related to inheritance (here, among other places).
Related videos on Youtube
![Pratik Bhoir](https://i.stack.imgur.com/i58Il.jpg?s=256&g=1)
Comments
-
Pratik Bhoir about 2 years
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.
-
Matthew Cox over 10 yearsThere is literally no difference. This is just various nomenclature used to discuss the topic of inheritance.
-
-
heltonbiker about 7 yearsMind that C# has "extension methods", which are not part of a given class, but count as "extending" it. That would imply a fundamental difference between "inheriting/subclassing" and "extending (in the sense of extension methods)".