Ticker

6/recent/ticker-posts

Inheritance in Python:

 Inheritance in Python:

Inheritance:

Inheritance allows defining a new class which inherits the properties methods from another class. New class is called the child class and the class from which it inherits is called as parent class. It helps in the reusability of the code.

Types of inheritance in python:

Single inheritance

Multiple inheritance

Multilevel inheritance

Hierarchical inheritance

Hybrid inheritance

Single inheritance:

There is only one parent class and one child class.

 

Example for single inheritance in Python

Multiple inheritance:

Here there is one child class and multiple parent classes. The child can inherit from multiple parent classes.

 

Example for multiple inheritance in Python

Multilevel inheritance:

Here there is chain of classes

Example for multilevel inheritance in python


 

Hierarchical inheritance:

Here there is a single parent and many child classes derived from parent class.

 

Example for hierarchical inheritance

Hybrid inheritance:

It is the combination of different types of inheritance.

 

Example for hybrid inheritance




Post a Comment

0 Comments