Abstract Classes Solution in C#

This Page Contains the Solution in CPP Programming Language for the Day 13 : Abstract Classes, Code Challange of the HackerRank 30 Days of Code.

using System;
using System.Collections.Generic;
using System.IO;
abstract class Book
{    
    protected String title;
    protected  String author;
    
    public Book(String t,String a){
        title=t;
        author=a;
    }
    public abstract void display();
}

//Write MyBook class
class MyBook : Book 
{
    private int price = 0;
    public MyBook(String title, String author, int price) : base(title, author) 
    {
        this.price = price;
    }
    public override void display() 
    {
        Console.Write("Title: {0} \nAuthor: {1} \nPrice: {2}", title, author, price);
    }
}

class Solution {
    static void Main(String[] args) {
      String title=Console.ReadLine();
      String author=Console.ReadLine();
      int price=Int32.Parse(Console.ReadLine());
      Book new_novel=new MyBook(title,author,price);
      new_novel.display();
    }
}

Last updated

Was this helpful?