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