class Post: # 親クラス Superクラス
def init(self, text):
self._text = text
self._likes = 0
def show(self):
print(f"{self._text} - {self._likes}")
def like(self):
self._likes += 1
class SponsoredPost(Post): # 子クラス Subクラス
def init(self, text, sponsor):
# self._text = text
# self._likes = 0
super().init(text)
self._sponsor = sponsor
def show(self):
print(f"{self._text} - {self._likes} sponsored by {self._sponsor}")
posts = [
Post(“Hello”),
Post(“Hi”),
SponsoredPost(“Hey”, “dotinstall”),
]
posts[2].like()
for post in posts:
post.show()