Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

HackerRank Day 13 Abstract Classes 30 days of code solution

YASH PAL, 31 July 2024

In this HackerRank Day 13 Abstract Classes 30 days of code problem set, we have two classes Book and Solution. we need to make a new class MyBook that inherited from Book and can print the details.

Day 13 Abstract Classes 30 days of code solution hackerrank

Problem solution in Python 2 programming.

#Write MyBook class
class MyBook(Book):
    def __init__(self,title,author,price):
        Book.__init__(self,title,author)
        self.price=price
    def display(self):
        print "Title: " + self.title
        print "Author: " + self.author
        print "Price: " + str(self.price)

Problem solution in Python 3 programming.

#Write MyBook class

class MyBook(Book):

    def __init__(self,title,author,price):
        self.title = title
        self.author = author
        self.price = price

    def display(self):
        print("Title:", title)
        print("Author:", author)
        print("Price:",price)

Problem solution in java programming.

class MyBook extends Book{
    int price;
    
    MyBook(String title, String author, int price){
        super(title, author);
        this.price = price;
    }
    
    public void display(){
        System.out.println(
                "Title: " + this.title + "n"
            +   "Author: " + this.author + "n"
            +   "Price: " + this.price
        );
    }
}

Problem solution in c++ programming.

//Write MyBook class
class MyBook : public Book {
    private:
        int price;
    
    public:
        MyBook(string title, string author, int price) : Book(title, author), price(price) {
            
        }
    
        void display(){
            cout << "Title: " << title << endl;
            cout << "Author: " << author << endl;
            cout << "Price: " << price << endl;
        }
};

Problem solution in Javascript programming.

// Declare your class here.
class MyBook extends Book{

    /**   
    *   Class Constructor
    *   
    *   @param title The book's title.
    *   @param author The book's author.
    *   @param price The book's price.
    **/
    // Write your constructor here
    constructor(title, author, price) {
        super(title, author);
        this.price = price;
    }
    /**   
    *   Method Name: display
    *   
    *   Print the title, author, and price in the specified format.
    **/
    // Write your method here
    display() {
        console.log('Title: ' + this.title);
        console.log('Author: ' + this.author);
        console.log('Price: ' + this.price);
    }
    
// End class
}
30 days of code coding problems

Post navigation

Previous post
Next post
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes