-
Notifications
You must be signed in to change notification settings - Fork 1
/
inheritance.py
55 lines (43 loc) · 1.31 KB
/
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
# # parent class definition
# class Engineer:
# def __init__(self, fname, lname):
# self.firstname = fname
# self.lastname = lname
#
# def printname(self):
# print(self.firstname, self.lastname)
#
#
# e1 = Engineer("Muhammad", "Ali")
# e1.printname()
#
#
# # child class
# class Software(Engineer):
# def __init__(self, fname, lname, profession): # the moment you call __init__ function in the child class,
# # the __init__of parent class is not derived'''
# self.profession = profession
# self.firstname = fname
# self.lastname = lname
#
# def professionalisation(self):
# print(self.firstname, self.lastname, self.profession)
#
#
# s1 = Software("Programmer", "Boy", "Python")
# s1.professionalisation()
class Engineer:
def __init__(self, fname, lname):
self.firstname = fname
self.lastname = lname
def printname(self):
print(self.firstname, self.lastname)
e1 = Engineer("Muhammad", "Ali")
e1.printname()
# child class
class Software(Engineer):
# To keep the inheritance of the parent's __init__() function, add a call to the parent's __init__() function:
def __init__(self, fname, lname):
Engineer.__init__(self, fname, lname) # that's it, too simple
s1 = Software("Programmer", "Boy")
s1.printname()