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 you try to solve it on your own first.
We'll cover the following
Problem Statement
There is a Book
class which has an abstract method getDetails()
, a parameterized constructor, and three protected fields:
- name
- author
- 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
Calls the constructor by passing name, author, and price.
Calls the `getDetails()` method to return the details of a book.
Output
Returns the details of a 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.