-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay_61 Inheritance in Python.py
141 lines (100 loc) · 3.39 KB
/
Day_61 Inheritance in Python.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# class Employee:
# def __init__(self, name, id):
# self.name = name
# self.id = id
# def showDetails(self):
# print(f'The name of Employee: {self.id} is {self.name}')
# class Programmer(Employee):
# def showLanguage(self):
# print('The default language is Python')
# e1 = Employee('Omkar', 400)
# e1.showDetails()
# e2 = Programmer('Karan', 5000)
# e2 = Employee('Karan Patel', 4100)
# e2.showDetails()
# e2.showLanguage()
# -----------------------------------------------------------------
# EXAMPLES
# -----------------------------------------------------------------
# Single Inheritance:
class Parent:
def func1(self):
print("This function is in parent class.")
class Child(Parent):
def func2(self):
print("This function is in child class.")
object = Child()
object.func1()
object.func2()
# -----------------------------------------------------------------
# Multiple Inheritance:
# class Mother:
# mothername = ""
# def mother(self):
# print(self.mothername)
# class Father:
# fathername = ""
# def father(self):
# print(self.fathername)
# class Son(Mother, Father):
# def parents(self):
# print("Father name is :", self.fathername)
# print("Mother name is :", self.mothername)
# s1 = Son()
# s1.fathername = "Ashok Patel"
# s1.mothername = "Bhavisha Patel"
# s1.parents()
# -------------------------------------------------------------------
# Multilevel Inheritance :
# class Grandfather:
# def __init__(self, grandfathername):
# self.grandfathername = grandfathername
# class Father(Grandfather):
# def __init__(self, fathername, grandfathername):
# self.fathername = fathername
# Grandfather.__init__(self, grandfathername)
# class Son(Father):
# def __init__(self, sonname, fathername, grandfathername):
# self.sonname = sonname
# Father.__init__(self, fathername, grandfathername)
# def print_name(self):
# print('Grandfather name :', self.grandfathername)
# print("Father name :", self.fathername)
# print("Son name :", self.sonname)
# s1 = Son('Karan Patel', 'Ashok Patel', 'Hasmukh Patel')
# print(s1.grandfathername)
# s1.print_name()
# ---------------------------------------------------------------------
# Hierarchical Inheritance:
# class Parent:
# def func1(self):
# print("This function is in parent class.")
# class Child1(Parent):
# def func2(self):
# print("This function is in child 1.")
# class Child2(Parent):
# def func3(self):
# print("This function is in child 2.")
# object1 = Child1()
# object2 = Child2()
# object1.func1()
# object1.func2()
# object2.func1()
# object2.func3()
# ----------------------------------------------------------------------
# Hybrid Inheritance:
# class School:
# def func1(self):
# print("This function is in school.")
# class Student1(School):
# def func2(self):
# print("This function is in student 1. ")
# class Student2(School):
# def func3(self):
# print("This function is in student 2.")
# class Student3(Student1, School):
# def func4(self):
# print("This function is in student 3.")
# object = Student3()
# object.func1()
# object.func2()