...
/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 {// Protected fieldsprotected String name;protected String author;protected String price;// Parameterized Constructorpublic Book(String name, String author, String price) {this.name = name;this.author = author;this.price = price;}// Abstract methodpublic abstract String getDetails();}// MyBook class extending Book classclass MyBook extends Book {// Parameterized constructorpublic MyBook(String name, String author, String price) {super(name, author, price); // Calling base class constructor}// Override the getDetails method of the Base Classpublic String getDetails() {return name + ", " + author + ", " + price;}}class Demo {public static void main(String args[]) {Book myBook = new MyBook("Harry Potter", "J.k. Rowling", "100");System.out.println(myBook.getDetails());}}
Explanation
- Line