Skip to content

Commit 78e2125

Browse files
some example
1 parent 775ac18 commit 78e2125

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# -------------------- CLASS RELATIONSHIP GRAPH --------------------
2+
#
3+
# Person Job
4+
# | |
5+
# | |
6+
# ------> Employee <---
7+
#
8+
# Employee inherits methods from both Person and Job
9+
# This is called MULTIPLE INHERITANCE
10+
# ------------------------------------------------------------------
11+
12+
13+
# Parent Class 1
14+
class Person:
15+
# Method to set the name
16+
def konda(self, name):
17+
self.name = name # storing name in the object
18+
19+
20+
# Parent Class 2
21+
class Job:
22+
# Method to set the salary
23+
def reddy(self, salary):
24+
self.salary = salary # storing salary in the object
25+
26+
27+
# Child Class (inherits from Person and Job)
28+
class Employee(Person, Job):
29+
30+
# Method to display details
31+
def details(self):
32+
print(self.name, "earns", self.salary)
33+
34+
35+
# -------------------- PROGRAM FLOW GRAPH --------------------
36+
#
37+
# emp = Employee()
38+
# |
39+
# v
40+
# emp.konda("konda") ---> sets name
41+
# |
42+
# v
43+
# emp.reddy(5000) ---> sets salary
44+
# |
45+
# v
46+
# emp.details() ---> prints output
47+
#
48+
# Object Memory:
49+
# emp
50+
# ├── name = "konda"
51+
# └── salary = 5000
52+
# ------------------------------------------------------------
53+
54+
55+
# Creating object
56+
emp = Employee()
57+
58+
# Calling method from Person class
59+
emp.konda("konda")
60+
61+
# Calling method from Job class
62+
emp.reddy(5000)
63+
64+
# Calling Employee class method
65+
emp.details()

0 commit comments

Comments
 (0)