FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
testing/sqlphp/developer-notes/python/python.oops.txt at main · astechedu/testing · GitHub
astechedu
/
testing
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
testing
/
sqlphp
/
developer-notes
/
python
/
python.oops.txt
Copy path
More file actions
More file actions
Latest commit
History
History
History
218 lines (117 loc) · 4.24 KB
Breadcrumbs
testing
/
sqlphp
/
developer-notes
/
python
/
python.oops.txt
Copy path
File metadata and controls
218 lines (117 loc) · 4.24 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
>>>> Python Oops <<<<<<
---------------------------------------------------------------------
Key: Oops,
---------------------------------------------------------------------
Types of inheritance Python:
Single Inheritance
Multiple Inheritance
Multilevel inheritance
Hierarchical Inheritance
Hybrid Inheritance
---------------------------------------------------------------------
---------------------------------------------------------------------
OOPs Exmple:
class Child1:
def __init__(self, name):
self.name = name
def getName1(self):
return self.name
def isStudent1(self):
return False
#Derived class or the Child class
class Student1(Child1):
def isStudent1(self):
return True
# An Object of Child
std = Child1("Jackie")
print(std.getName1(), std.isStudent1())
# An Object of Student
std = Student1("johnny")
print(std.getName1(), std.isStudent1())
---------------------------------------------------------------------
1. Single Inheritance:
# Here, we will create the base class or the Parent class
class Parent1:
def func_1(self):
print ("This function is defined inside the parent class.")
# now, we will create the Derived class
class Child1(Parent1):
def func_2(self):
print ("This function is defined inside the child class.")
# Driver's code
object = Child1()
object.func_1()
object.func_2()
--------------------------------------------------------------------
2. Multiple Inheritance
# Here, we will create the Base class 1
class Mother1:
mothername1 = ""
def mother1(self):
print(self.mothername1)
# Here, we will create the Base class 2
class Father1:
fathername1 = ""
def father1(self):
print(self.fathername1)
# now, we will create the Derived class
class Son1(Mother1, Father1):
def parents1(self):
print ("Father name is :", self.fathername1)
print ("Mother name is :", self.mothername1)
# Driver's code
s1 = Son1()
s1.fathername1 = "Rajesh"
s1.mothername1 = "Shreya"
s1.parents1()
--------------------------------------------------------------------
3. Multilevel inheritance
# Here, we will create the Base class
class Grandfather1:
def __init__(self, grandfathername1):
self.grandfathername1 = grandfathername1
# here, we will create the Intermediate class
class Father1(Grandfather1):
def __init__(self, fathername1, grandfathername1):
self.fathername1 = fathername1
# here, we will invoke the constructor of Grandfather class
Grandfather1.__init__(self, grandfathername1)
# here, we will create the Derived class
class Son1(Father1):
def __init__(self,sonname1, fathername1, grandfathername1):
self.sonname1 = sonname1
# here, we will invoke the constructor of Father class
Father1.__init__(self, fathername1, grandfathername1)
def print_name(self):
print('Grandfather name is :', self.grandfathername1)
print("Father name is :", self.fathername1)
print("Son name is :", self.sonname1)
# Driver code
s1 = Son1('John', 'John Jr', 'John Jr Jr')
print (s1.grandfathername1)
s1.print_name()
----------------------------------------------------------------------------------
4. Hierarchical Inheritance
# Here, we will create the Base class
class Parent1:
def func_1(self):
print ("This function is defined inside the parent class.")
# Derived class1
class Child_1(Parent1):
def func_2(self):
print ("This function is defined inside the child 1.")
# Derivied class2
class Child_2(Parent1):
def func_3(self):
print ("This function is defined inside the child 2.")
# Driver's code
object1 = Child_1()
object2 = Child_2()
object1.func_1()
object1.func_2()
object2.func_1()
object2.func_3()
----------------------------------------------------------------------------------
5. Hybrid Inheritance:
https://www.educative.io/answers/what-is-hybrid-inheritance-in-python
---------------------------------------------------------------------------------
Back
|
FazBrowse Home
|
New Git URL