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

Commit7e1cf9d

Browse files
committed
Add demo for inheritance using class Phone and Mobile_phone
1 parent8a75a72 commit7e1cf9d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

‎SimpleOOP/src/simpleoop.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,31 @@ def set_variable(self, k, v):
6060
print('Key-value argument makes the class model easily scalable in python.')
6161
self.variables[k]=v
6262

63+
classPhone:
64+
def__init__(self):
65+
print('parent class')
66+
67+
defbuttons(self):
68+
print('Has buttons to dial a number.')
69+
70+
defscreen(self):
71+
print('Phone has a black and white display!')
72+
73+
classMobile_phone(Phone):
74+
def__init__(self):
75+
print('Child class of Phone')
76+
77+
definternet_connection(self):
78+
print('Can connect to internet using WiFi!')
79+
80+
defbuttons(self):
81+
print('Buttons on touch screen! -> Overriding buttons from Parent class Phones!')
82+
83+
defscreen(self):
84+
super().screen()# method to access parent class methods
85+
print('Display is colored as a whole.')
86+
87+
6388
defmain():
6489
# instantiate: make object of the class
6590
f=Fibonacci(0,1)
@@ -84,4 +109,17 @@ def main():
84109
marty.set_variable('intelligence','VeryHighIntell')
85110
print('Getting new value of\'intelligence\':',marty.get_variable('intelligence'))
86111

112+
print()
113+
print('Explaining Inheritance in Python OOP:')
114+
telepone=Phone()
115+
print('Methods of obj telephone:')
116+
telepone.buttons()
117+
telepone.screen()
118+
samsung=Mobile_phone()
119+
print('Methods of derived class:')
120+
samsung.internet_connection()
121+
samsung.buttons()
122+
samsung.screen()
123+
124+
87125
if__name__=='__main__':main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp