Hackerrank 30 days of code Java Solution: Day 13: Abstract Classes

The next problem is based on abstract classes. Abstract classes are class declared as abstract which abstract or defined methods.Abstract classes cannot be instantiated but that can be subclassed.  According to oracle documentation: When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, then the subclass must also be declared abstract.

The objective of this day is to make us aware of the basic implementation of the 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 
    2. string 
    3. int 
  • Implements the Book class’ abstract display() method so it prints these  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

Sample Output

So here the Solution you have landed here for..

Thanks for the visit checkout the day 14 tutorial as well.. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *