Python Programming – Inheritance

In the previous chapter, we have learned the designing of classes and objects in Python. Reusability or inheritance is one of the most significant features of OOPS. It is a good practice to reuse something which already exists rather than creating the new one all over again. It would not save only time and energy but also increases reliability, as the already build code is previously tested and debugged. Alike, C++ and Java, Python classes also use the concept of inheritance. Inheritance enables us to define a class that takes all the functionality and features of the base class. The base class is known as the parent class or superclass and the derived class is also known as the child class or subclass. Here in this section, we will learn the concept of using inheritance in detail. The general syntax of using inheritance is given as follows:

class DerivedClass(BaseClass):
Body of Derived Class

The above syntax is quite simpler than that is used in C++ and Java for inheriting classes. The derived class represents the new class and the BaseClass represents the old class followed by a colon. The body of the class begins with indentation. The inheritance can be categorized into the single inheritance, multiple inheritance, and multilevel inheritance. Each of them is described in the following sections.

Summary

In this chapter, one of the significant features of OOPS known as inheritance is elaborated. Single, multiple, and multilevel inheritance are described with the programming illustration of each. The concept of method overriding is also discussed.

Python Tutorial

Leave a Reply

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