Class Inheritance

What is a Class Inheritance?

An inheritance allows us to define a class that inherits all the methods and properties from another class.

Parent Class

Parent class is the class the child will be inheriting from (i.e., class that is being extended to create a new class), also called base class. Contributes all the methods and attributes to the new child class.

Child Class

Child class is the new class create when a parent class is extended. The child inherits all the attributes and methods of the parent that will make up the object. This is different from Creating Subclasses.

How to create a child class?

To create a class that inherits the functionality from another class, we can send the parent class as a parameter when creating the child class:

class child_class(parent_class):  
  pass

We use the pass keyword when you do not want to add any other properties or methods to the class.

The new class will now have all the same properties and methods as the parent class.

Powered by Forestry.md