-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiple_inheritence_example.py
More file actions
65 lines (51 loc) · 1.42 KB
/
multiple_inheritence_example.py
File metadata and controls
65 lines (51 loc) · 1.42 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
# -------------------- CLASS RELATIONSHIP GRAPH --------------------
#
# Person Job
# | |
# | |
# ------> Employee <---
#
# Employee inherits methods from both Person and Job
# This is called MULTIPLE INHERITANCE
# ------------------------------------------------------------------
# Parent Class 1
class Person:
# Method to set the name
def konda(self, name):
self.name = name # storing name in the object
# Parent Class 2
class Job:
# Method to set the salary
def reddy(self, salary):
self.salary = salary # storing salary in the object
# Child Class (inherits from Person and Job)
class Employee(Person, Job):
# Method to display details
def details(self):
print(self.name, "earns", self.salary)
# -------------------- PROGRAM FLOW GRAPH --------------------
#
# emp = Employee()
# |
# v
# emp.konda("konda") ---> sets name
# |
# v
# emp.reddy(5000) ---> sets salary
# |
# v
# emp.details() ---> prints output
#
# Object Memory:
# emp
# ├── name = "konda"
# └── salary = 5000
# ------------------------------------------------------------
# Creating object
emp = Employee()
# Calling method from Person class
emp.konda("konda")
# Calling method from Job class
emp.reddy(5000)
# Calling Employee class method
emp.details()