In this HackerRank Java Abstract Class problem, we need to create another class MyBook that extends the abstract class. and then we need to create an instance of the new class.

HackerRank Java Abstract Class problem solution

HackerRank Java Abstract Class problem solution

import java.util.*;

abstract class Book{
  String title;
  abstract void setTitle(String s);
  String getTitle(){
    return title;

//Write MyBook class here
class MyBook extends Book{
  public void setTitle(String title) {
    this.title = title;

public class Main{
   public static void main(String []args){
      //Book new_novel=new Book(); This line error: Book is abstract; cannot be instantiated
      Scanner sc=new Scanner(;
      String title=sc.nextLine();
      MyBook new_novel=new MyBook();
      System.out.println("The title is: "+new_novel.getTitle());