Skip to content

Commit c68cad7

Browse files
author
Vimal
committed
* Added 40-super-1.py
1 parent 50dda64 commit c68cad7

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

40-super-1.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python
2+
3+
# 40-super-1.py
4+
5+
# This is an example on how super() works
6+
# in Inheritance.
7+
8+
# For more step-by-step details, refer :
9+
# https://arvimal.wordpress.com/2016/07/01/inheritance-and-super-object-oriented-programming/
10+
11+
12+
class MyClass(object):
13+
14+
def func(self):
15+
print("I'm being called from the Parent class")
16+
17+
18+
class ChildClass(MyClass):
19+
20+
def func(self):
21+
print("I'm actually being called from the Child class")
22+
print("But...")
23+
# Calling the `func()` method from the Parent class.
24+
super(ChildClass, self).func()
25+
26+
my_instance_2 = ChildClass()
27+
my_instance_2.func()
28+

0 commit comments

Comments
 (0)