Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 40a8278

Browse files
INheri
1 parent 656e2f2 commit 40a8278

File tree

1 file changed

+84
-2
lines changed

1 file changed

+84
-2
lines changed

‎Class.ipynb‎

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,18 @@
131131
},
132132
{
133133
"cell_type": "code",
134-
"execution_count": null,
134+
"execution_count": 11,
135135
"metadata": {},
136-
"outputs": [],
136+
"outputs": [
137+
{
138+
"name": "stdout",
139+
"output_type": "stream",
140+
"text": [
141+
"Parrot can fly\n",
142+
"Penguin can't fly\n"
143+
]
144+
}
145+
],
137146
"source": [
138147
"### Polymorphism \n",
139148
"class Parrot:\n",
@@ -164,6 +173,79 @@
164173
"flying_test(blu)\n",
165174
"flying_test(peggy)"
166175
]
176+
},
177+
{
178+
"cell_type": "code",
179+
"execution_count": 16,
180+
"metadata": {},
181+
"outputs": [
182+
{
183+
"name": "stdout",
184+
"output_type": "stream",
185+
"text": [
186+
"Rahul\n"
187+
]
188+
}
189+
],
190+
"source": [
191+
"# Python program to demonstrate error if we \n",
192+
"# forget to invoke __init__() of parent. \n",
193+
"\n",
194+
"class A: \n",
195+
" def __init__(self, n = 'Rahul'): \n",
196+
" self.name = n \n",
197+
"class B(A): \n",
198+
" def __init__(self, roll): \n",
199+
" A.__init__(self)\n",
200+
" self.roll = roll \n",
201+
"\n",
202+
"object = B(23) \n",
203+
"print(object.name) \n"
204+
]
205+
},
206+
{
207+
"cell_type": "code",
208+
"execution_count": 38,
209+
"metadata": {},
210+
"outputs": [
211+
{
212+
"name": "stdout",
213+
"output_type": "stream",
214+
"text": [
215+
"B\n"
216+
]
217+
}
218+
],
219+
"source": [
220+
"\n",
221+
"\n",
222+
"class A: \n",
223+
" def __init__(self, n = 'A'): \n",
224+
" self.name = n \n",
225+
"class B: \n",
226+
" def __init__(self, n = 'B'): \n",
227+
" self.name = n \n",
228+
"class D: \n",
229+
" def __init__(self, n = 'D'): \n",
230+
" self.name = n \n",
231+
"\n",
232+
"class C(A,B,D):\n",
233+
" # def __init__(self): \n",
234+
" # A.__init__(self)\n",
235+
" # B.__init__(self)\n",
236+
" pass\n",
237+
" \n",
238+
"\n",
239+
"object = C()\n",
240+
"print(object.name) \n"
241+
]
242+
},
243+
{
244+
"cell_type": "code",
245+
"execution_count": null,
246+
"metadata": {},
247+
"outputs": [],
248+
"source": []
167249
}
168250
],
169251
"metadata": {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /