Patrick's Blog

Patrick's Blog

What is Inheritance?

What comes to mind when YOU hear the word Inheritance?

The concept of inheritance could also be applied to real life aspects, for example: Money, Genetics, Culture Inheritance etc..

Inheritance is what gives a class the ability to extend itself to a child class, as well as being one of the most important parts of Object-Oriented Programming, you could consider child classes like an evolution of a parent class.

Enabling us to create new objects that take on properties of an existing object, the same way Object is the parent class of every class in C#.

image.png

Why would you want to use Inheritance?

  • Saves time.
  • Reduces the chance of errors.
  • Makes it easier to understand the inherited class.
  • Makes programs easier to write.

Terminology

  • Base Class: A class that is used as a basis for inheritance (The parent class).

  • Derived Class: A class that inherits from a base class (The child class). It must always be "is a" case or an instance of the more general base class.

-Ancestors: A list of parent classes from which a child class is derived, Inheritance being transitive. A child Inherits all the members of all its ancestors.

 
Share this