Object oriented programming has a few core concepts. One of the most fundamental is Inheritance. Here’s a really simple explanation:

  • Inheritance is using existing classes as the foundation of new classes.

Once again, a real world example would be good here.

Let’s say you have a blueprint to create a ‘Car’. The blueprint contains instructions as follows:

  • X number of wheels
  • Y number of doors
  • Z top speed

Then let’s say you want a new blueprint to create a ‘Fast Car’ that had an extra property of ‘Color = Red’. Do you think it’s wise to copy over the basic ‘Car’ blueprint and modify it for a ‘FastCar’ just to add the color red? Well no, you’d be repeating the same information. What if someone changes the basic car configuration? You’d need to ALSO change it for ‘Fast Car’.

Time for a code example, the basic ‘Car’:

And now for the ‘FastCar’ which inherits from ‘Car’:

Now FastCar has inherited all the properties / functions / whatevers from ‘Car’. Neat right?

So in summary, the basic idea of inheritance?

Don’t repeat code.

What is Inheritance – Object Oriented Programming

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share This

Exhausted by your 9 - 5?

Would you prefer to work for half the time and earn double? The first step to your freedom is understanding how apps make money. Simply enter your email below and I will send you a free PDF describing the process.

If you're serious about improving your life then do not miss this opportunity.


You have subscribed! Please check your email to confirm this subscription and to receive your item!