Course Object Oriented Programming

Pillar 3: Inheritance

Course's Page 5 min Text by
User Image
Abacate

In this class you will learn the 3rd pillar of Object-Oriented Programming (OOP): Inheritance.

What is it?

In OOP, inheritance is used for one class to inherit characteristics from another class. In other words, when a class B inherits from a class A, the class B will have everything, all the methods and attributes, that the class A has, plus its specific characteristics.

When a class B inherits from a class A:

  • Class base (or parent): A.
  • Class derived (or child): B.

Example

Imagine that we have already defined a class person, and now we want to create a class student.

As a student is a person, the student will have all the characteristics of a person plus the characteristics of a student. In this way, it is not necessary to re-code all the characteristics in common.

Why to use inheritance?

  1. Avoid rewriting the characteristics of the parent class in the child class.