1+ # ------------------ INHERITANCE STRUCTURE ------------------
2+ #
3+ # Person
4+ # |
5+ # Employee
6+ # |
7+ # TeamLead
8+ # |
9+ # Project
10+ #
11+ # TeamLead inherits from Employee and Project
12+ # Employee already inherits from Person
13+ # This combination is called HYBRID INHERITANCE
14+ # -----------------------------------------------------------
15+
16+
17+ # Base class
18+ class Person :
19+ # Constructor to store the person's name
20+ def __init__ (self , name ):
21+ self .name = name
22+
23+
24+ # Employee class inherits from Person
25+ class Employee (Person ):
26+ # Method to show role
27+ def role (self ):
28+ print (self .name , "is an employee" )
29+
30+
31+ # Another independent class
32+ class Project :
33+ # Method to store project name
34+ def project_details (self , project_name ):
35+ self .project_name = project_name
36+
37+
38+ # TeamLead inherits from Employee and Project
39+ class TeamLead (Employee , Project ): # Hybrid Inheritance
40+ # Method to display project leadership details
41+ def details (self ):
42+ print (self .name , "leads project:" , self .project_name )
43+
44+
45+ # ------------------ PROGRAM FLOW ------------------
46+ #
47+ # lead = TeamLead("Konda")
48+ # |
49+ # |-- Person.__init__() runs
50+ # | self.name = "Konda"
51+ # |
52+ # lead.role()
53+ # |
54+ # |-- prints employee role
55+ #
56+ # lead.project_details("MNC project")
57+ # |
58+ # |-- stores project name
59+ #
60+ # lead.details()
61+ # |
62+ # |-- prints project leadership details
63+ # --------------------------------------------------
64+
65+
66+ # Create object of TeamLead
67+ lead = TeamLead ("Konda" )
68+
69+ # Call method from Employee class
70+ lead .role ()
71+
72+ # Call method from Project class
73+ lead .project_details ("MNC project" )
74+
75+ # Call method from TeamLead class
76+ lead .details ()
0 commit comments