What is method overload in Python

Python course


Introduction and Definitions

No object-oriented programming language would be worth looking at or used if it does not support inheritance. Inheritance was invented for Simula in 1969. Not only does Python support inheritance, it also supports multiple inheritance. In general, inheritance is the mechanism for inferring new classes from existing ones. In this way we get a hierarchy of classes. In most class-based object-oriented languages, an object created by inheritance (a "child"), although there are exceptions in some programming languages, captures all of the properties and behaviors of the parent object.

Inheritance allows programmers to create classes that build on existing classes. In this way, a class created through inheritance can inherit the attributes and methods of the parent class. This means that inheritance helps code reusability. The methods inherited from a subclass, or in general the software inherited from a subclass, are considered to be reused in the subclass. The relationships of objects or classes through inheritance lead to a directed graph.

The class from which a class inherits is called the parent class. A class that inherits from a superclass is called a subclass, also known as an inheritor class or child class. Superclasses are also sometimes called ancestors. There is a hierarchical relationship between classes. It is similar to relationships or categorizations that we know from real life. Think of vehicles, for example. Bicycles, cars, buses, and trucks are vehicles. Pick-ups, delivery vans, sports cars, convertibles and station wagons are all cars and, as cars, vehicles too. We could implement a vehicle class in Python that could have methods like acceleration and braking. Cars, buses and trucks and bicycles can be implemented as subclasses that inherit these methods from the vehicle.

Inheritance syntax in Python

The syntax for a subclass definition is as follows: