This exercise is part of HackerRank 30 days of Code - Day 13 Abstract Class C#
I am trying to understand the reason why we have to define an int price = 0 in this case when we did not have to do the same for the title and author for example. Why we can't just pass the parameter using :base as we did with title and author?
Here is the code in C#:
class MyBook : Book {
public int price = 0;
public MyBook(String title, String author, int price)
: base(title, author)
{
this.price = price;
}
public override void display()
{
Console.WriteLine($"Title: {title}");
Console.WriteLine($"Author: {author}");
Console.WriteLine($"Price: {price}");
}
}
Thank you for your help!