hierarchical inheritance in python

preview_player
Показать описание
In this video you will learn types of inheritance in python. I will teach you how to implement single inheritance and multilevel inheritance.

Hierarchical Inheritance
In the hierarchical inheritance, a parent class have more than one children. In other words we can also say that if more than one classes are inherited from a same parent class, then it is called as hierarchical inheritance.

In this example the Student and Player are inherited from Person class. Here Student and Player are called siblings of each other. Both student and player receives the features from Person and can also add their own features.
The following program demonstrates the concept of hierarchical inheritance:

class Person:
def __init__(self,name,age):

def printPersonalDetails(self):

class Student(Person):
def __init__(self,name,age,roll,college):
Person.__init__(self,name,age)
def printStudentDetails(self):

class Player(Person):
def __init__(self,name,age,matches,sportname):
super().__init__(name,age)
def printPlayerDetails(self):

s=Student("Tarun Verma",32,1234,"NIELIT")

p=Player("Devanshu Sharma",20,35,"Chess")

#python_by_tarun_sir #tarun_sir #python #tarun_sir_python #python_video_66 #hierarchical_inheritance_in_python #python_tutorial #siblings_in_python #super()_in_python
Рекомендации по теме
welcome to shbcf.ru