Movatterモバイル変換


[0]ホーム

URL:


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

Commit12a67a0

Browse files
committed
Add demo of polymorphism.
1 parent7e1cf9d commit12a67a0

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

‎SimpleOOP/src/simpleoop.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,34 @@ def buttons(self):
8383
defscreen(self):
8484
super().screen()# method to access parent class methods
8585
print('Display is colored as a whole.')
86+
87+
classRose:
88+
defcolor(self):
89+
print('Rose is Red.')
90+
defsmell(self):
91+
print('Rose has a sweet smell.')
92+
defstem(self):
93+
print('Stem of rose have thorns.')
94+
deflocation(self):
95+
print('Rose in the garden.')
96+
97+
classLotus:
98+
defcolor(self):
99+
print('Lotus is pink.')
100+
defsmell(self):
101+
print('Lotus has no smell.')
102+
defstem(self):
103+
print('Stem of lotus has no thorns.')
104+
deflocation(self):
105+
print('Lotus in the pond.')
86106

107+
defwhat_location_n_color(lotus):
108+
lotus.location()
109+
lotus.color()
87110

111+
defsmell_the_flower(rose):
112+
rose.smell()
113+
88114
defmain():
89115
# instantiate: make object of the class
90116
f=Fibonacci(0,1)
@@ -121,5 +147,15 @@ def main():
121147
samsung.buttons()
122148
samsung.screen()
123149

150+
print()
151+
print('Explaining POLYMORPHISM in python:')
152+
print('Python being loosely typed language, polymorphism is inherent in this language.')
153+
redrose=Rose()
154+
redlotus=Lotus()
155+
foroin (redrose,redlotus):
156+
what_location_n_color(o)
157+
smell_the_flower(o)
158+
o.color()
159+
124160

125-
if__name__=='__main__':main()
161+
if__name__=='__main__':main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp