...
/Solution Review: Implement an Abstract Method in a Base Class
Solution Review: Implement an Abstract Method in a Base Class
This review provides a detailed analysis to solve the 'Implement an Abstract Method in a Base Class' challenge.
We'll cover the following...
Solution
Press + to interact
// Abstarct Book Classabstract class Book {// Private Fieldsprivate string _name;private string _author;private string _price;protected string Name{get {return this._name;}}protected string Author{get {return this._author;}}protected string Price{get {return this._price;}}// Parameterized Constructorpublic Book(string name, string author, string price) {this._name = name;this._author = author;this._price = price;}// Abstract Methodpublic abstract string GetDetails();}// Class MyBook extending Book Classclass MyBook : Book {// Parameterized Constructorpublic MyBook(string name, string author, string price): base(name, author, price){ }// Overrideing the GetDetails Abstract Method of the Base Classpublic override string GetDetails() {return Name + ", " + Author + ", " + Price;}}class Demo {public static void Main(string[] args) {Book myBook = new MyBook("Harry Potter", "J.k. Rowling", "100");Console.WriteLine(myBook.GetDetails());}}
Explanation
- Line 32: