Multiple Inheritance में एक से अधिक base classes हो सकते है और एक derived class होता है |
Derived class को दो या दो से ज्यादा base classes को inherit किया जाता है, उसे Multiple Inheritance कहते है |
Multiple Inheritance में एक Child Class और उसके एक से ज्यादा Parent Classes को inherit करता है |
Source Code :
Derived class को दो या दो से ज्यादा base classes को inherit किया जाता है, उसे Multiple Inheritance कहते है |
Multiple Inheritance में एक Child Class और उसके एक से ज्यादा Parent Classes को inherit करता है |
Syntax for Multiple Inheritance
class Base1: Base1_Class_Body class Base2: Base2_Class_Body class Derived(Base2,Base1): Derived_Class_Body
Example for Multiple Inheritance
Example पर Employee और Fitness ये दो Base class है और उनका एक ही derived class है जो दोनों base class की properties को inherit करता है |Source Code :
#Base class of Company
class Employee:
def set1(self,empid,name,salary):
self.empid = empid
self.name = name
self.salary = salary
#Base class of Company
class Fitness:
def set2(self,height,weight):
self.height = height
self.weight = weight
#Derived class of Fitness and Employee
class Company(Fitness,Employee):
def set3(self,company,dep):
self.company = company
self.dep = dep
def display(self):
print("id :",self.empid)
print("name :",self.name)
print("salary :",self.salary,"Rs")
print("height :",self.height,"cm")
print("weight :",self.weight,"kg")
print("Company :",self.company)
print("Department :",self.dep)
obj = Company()
obj.set1(1,"Rakesh",27000)
obj.set2(176,60)
obj.set3("Infosys", "IT")
obj.display()
Output :
id : 1 name : Rakesh salary : 27000 Rs height : 176 cm weight : 60 kg Company : Infosys Department : IT







No comments: