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 51beb9d

Browse files
Re-visiting method overloading, made more readable
1 parent 2e232d1 commit 51beb9d

File tree

1 file changed

+47
-9
lines changed

1 file changed

+47
-9
lines changed

‎OOP/Polymorphism/MethodOverriding.py

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,57 @@
11

2-
class A(object):
2+
class Father(object):
33

44
def __init__(self, a, b):
55
self.a = a
66
self.b = b
77

8-
def m1(self):
9-
print"inside A"
8+
def role(self):
9+
print("Father of two childres")
1010

11-
class B(A):
11+
def occupation(self):
12+
print("Father is working in Bank")
1213

13-
def __init__(self):
14+
def travellingIn(self):
15+
print("As a father, I use Audi Car to go office")
16+
17+
class Mother(Father):
18+
19+
def __init__(self,):
1420
print ("b constructor")
15-
# def m1(self):
16-
# print "inside b"
1721

18-
bb = B()
19-
bb.m1()
22+
def role(self):
23+
print("Mother of Two childrens")
24+
25+
def occupation(self):
26+
print("Home maker")
27+
28+
def whatCooking(self):
29+
print("Mother is preparing Pasta!")
30+
31+
# creating an object of mother.
32+
instanceOfMother = Mother()
33+
34+
instanceOfMother.role()
35+
36+
instanceOfMother.occupation()
37+
38+
instanceOfMother.whatCooking()
39+
40+
instanceOfMother.travellingIn()
41+
42+
43+
# creating an object of Father
44+
45+
fatherInstance = Father(10,20)
46+
47+
fatherInstance.role()
48+
49+
fatherInstance.travellingIn()
50+
51+
fatherInstance.occupation()
52+
53+
fatherInstance.whatCooking()
54+
55+
56+
# how about this?
57+
print(bb.a)

0 commit comments

Comments
(0)

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