30 Day code challenge-python

Day 13–Abstract Classes


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:
  1. string title
  2. string author
  3. int price
  • Implements the Book class’ abstract display() method so it prints these 3 lines:
  1. Title, a space, and then the current instance’s title.
  2. Author, a space, and then the current instance’s author.
  3. Price, a space, and then the current instance’s price.
Sample input and output

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).



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



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store