Object Oriented Programming Inheritance

This is the fourth part of the OOP primer series, where we discuss the concept of Inheritance and the idea that objects being able to inherit certain pieces of data from their ‘parent’ object.

As always, if there are any comments please feel free to email me.

Inheritance Going back to the “you” object, I really like your hair, it fits you and it matches your eyes very well. Did you get your hair texture from your mom? Your dad? Maybe it’s a mix of both, maybe you Inheritted both of the traits from your mom and your dad. Inheritance is the OOP concept that any child class can have the same data and methods as the parent class before them. So let’s say you inherited your hair texture from your mom, and your mom inherited their hair texture from their mom, so on and so forth until we get to the first person who has ever existed whose name is “Person”.

Now “Person” was the first one who has ever had a name (“Person”), an age, and other characteristics that can be only found in them (The ability to walk, the ability to eat, etc.). Because “Person” is your great\^n-parent, you inherited some of their characteristics such as the ability to walk, but also have characteristics of your own such as the ability to play the computer and a social security number. With Inheritance, the child classes do take on the characteristics of the parent class, but they can also add their own characteristics that may be only found in them or can only be inherited through a long lineage of inheritance. In OOP, this line of inheritance is the same; the child class inherits the data of the parent class, but the child class can modify and add to this data if need be.

Written on March 4, 2023