Inheritance in Python



Inheritance

Inheritance is the important property of object-oriented programming that imparts the ability to a class to inherit properties and behaviour of another class. Inheritance is the property by which the objects of the derived class posses the copies of the data members and member functions of the base class.


Syntax:

Class base:
    >Statement<
class Derived(base):
    >Statement<

For example: 

class Employee:
    def Sallary(self):
        print("Sallary is : 54000")
class Person(Employee):
    def Name(self):
        print("Name is : John")
Per_Info=Person()
Per_Info.Sallary()
Per_Info.Name()

 


Base class:

A base class is actually a superclass and the class from which it is derived is called a Base, super or a parent class.

Derived class:

A derived class is a subclass. A class that inherits or derives attributes from another class is called Derived, sub or a child class.

Types of Inheritance in Python

1.Single Inheritance.
2.Multiple Inheritance.
3.Multilevel Inheritance.
4.Hierarchical Inheritance.
5.Hybrid Inheritance.

Post a Comment

0 Comments