Challenge 1: Implement an Abstract Method in a Base Class
Can you implement an abstract method of a base class? A solution is placed in the solution section to help you, but we would suggest that you try to solve it on your own first.
We'll cover the following
Problem Statement
We have already implemented a Book
class which has an abstract method, GetDetails()
, a parameterized constructor, and three private fields having their respective properties with get
accessors defined:
_name
with the property,Name
_author
with the property,Author
_price
with the property,Price
Write a MyBook
class that inherits from the Book
class and has a parameterized constructor taking these parameters:
- string title
- string author
- string price
Implement the Book
class’ getdetails()
method in the MyBook
class so that it returns the MyBook
details.
Input
Call to MyBook constructor passing name, author, and price.
Call to `GetDetails()` method to return the details of a book.
Output
Returns the details of the book.
Sample Input
Book myBook = new MyBook("Harry Potter", "J.k. Rowling", "100");
Sample Output
"Harry Potter, J.k. Rowling, 100"
Get hands-on with 1400+ tech skills courses.