-
Notifications
You must be signed in to change notification settings - Fork 1
/
class_inheritance.py
68 lines (56 loc) · 2.01 KB
/
class_inheritance.py
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
# Parent aur child
class ParentClass:
def __init__(self, fatherName, motherName):
self.father = fatherName
self.mother = motherName
# Introduce to childs parent
def parentIntroduction(self):
introduction = '''
-----------------------------------
Introduc to Prent Class
-----------------------------------
Father's Name: {}
Mohter's Name: {}
'''.format(self.father, self.mother)
print(introduction)
# Crate parent class object
# After cerating child calss and class form child class. comment line 22 to 26
# father = 'Ram'
# mohter = 'Sita'
# parentObj = ParentClass(father, mohter)
# # Call parentIntroduction method
# parentObj.parentIntroduction()
# Create anohter class
# Know convert this another class into child class
class ChildClass(ParentClass):
def __init__(self, fatherName, motherName, childName):
self.child = childName
# Call parent class constructer
# ParentClass.__init__(self, fatherName, motherName)
# use super() fucntio to pass requried values to parent class constructer
# super() fucntion no need to user preant class name and self argument
super().__init__(fatherName, motherName)
def ayseHiFunctionBanaDiay():
print('\nayseHiFunctionBanaDiay')
def childIntroduction(self):
introduction = '''
------------------------------
Child Inroduction
------------------------------
First Child Name: {}
Second Child Name: {}
'''.format(self.child[0], self.child[1])
print(introduction)
# ayseHiFunctionBanaDiay()
self.ayseHiFunctionBanaDiay()
# Create child class object to pass requerd arguemt and call related method
# father = 'Ram'
# mohter = 'Sita'
# child = 'Love','Kush'
# childObj = ChildClass(father, mohter, child)
# # call method
# childObj.parentIntroduction()
# childObj.childIntroduction()
# Home work:
# local scope of method
# global scope of method