A method that only the child class has
Predict the output · Medium · §11.5 When you need a class
The event post class Event inherits from the post class Post. Predict the output without running the code.
Code
class Post:
def __init__(self, author):
self.author = author
self.likes = 0
def like(self):
self.likes += 1
def __str__(self):
return f"{self.author}: {self.likes} likes"
class Event(Post):
def boost(self):
self.like()
self.like()
e = Event("mina")
e.boost()
e.like()
print(e)
p = Post("jun")
p.boost()
print(p)Solve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.