30 Day code challenge-python
Day 13–Abstract Classes
Task
Given a Book class and a Solution class, write a MyBook class that does the following:
- Inherits from Book
- Has a parameterized constructor taking these parameters:
- string title
- string author
- int price
- Implements the Book class’ abstract display() method so it prints these 3 lines:
- Title, a space, and then the current instance’s title.
- Author, a space, and then the current instance’s author.
- Price, a space, and then the current instance’s price.
Input Format
You are not responsible for reading any input from stdin. The Solution class creates a Book object and calls the MyBook class constructor (passing it the necessary arguments). It then calls the display method on the Book object.
Output Format
The void display() method should print and label the respective title, author, price and of the MyBook object’s instance (with each value on its own line).
Explanation
Line 15–17: Gets input from the user
Line 18: Calls the class MyBook which inherits the class Book.
Line 9–14: Prints the output in the required format where MyBook class inherits the value of class Book using super function.
Bonus Tip: Abstract class is imported from ABC (Abstract Base Class) module and it’s denoted as @abstractmethod. For an abstractmethod object can’t be created.
See you on day 14