Difference between Class Inherit, extend and implement oops

17,216

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).

Share:
17,216

Related videos on Youtube

Pratik Bhoir
Author by

Pratik Bhoir

Hello

Updated on June 05, 2022

Comments

  • Pratik Bhoir
    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
      Matthew Cox over 10 years
      There is literally no difference. This is just various nomenclature used to discuss the topic of inheritance.
  • heltonbiker
    heltonbiker about 7 years
    Mind 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)".