sponsor

sponsor

Slider

Recent Tube

Business

Technology

Life & style

Games

Sports

Fashion

» » Python Multilevel Inheritance

Multilevel Inheritance में एक base class और दो derived class होते है |
Multilevel Inheritance में derived class का एक base class होता है और derived class का भी एक derived class होता है |

Syntax for Multilevel Inheritance

class Base:
 Base_Class_Body
class Derived1(Base):
 Derived1_Class_Body
class Derived2(Derived1):
 Derived2_Class_Body

Example for Multilevel Inheritance

Example पर Employee class के Fitness और Company ये दो derived class है |
उसके बाद Fitness इस class का एक base class(Employee) और एक derived class(Company) है |
उसके बाद Company इस class के Fitness और Employee ये दो base class है | Company class ये Fitness और Employee की properties को inherit करता है |
सिर्फ Company class का object Fitness और Employee इन दोनों की properties को access करता है |
Source Code :
#Base class of Fitness and Company
class Employee:
    def set1(self,empid,name,salary):        
        self.empid = empid
        self.name = name
        self.salary = salary

#Base class of Company and Derived class of Employee
class Fitness(Employee):
    def set2(self,height,weight):
        self.height = height
        self.weight = weight

#Derived class of Fitness and Employee
class Company(Fitness):
    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

«
Next
Newer Post
»
Previous
Older Post

No comments:

Leave a Reply