biryu2205 / Biryu

0 stars 0 forks source link

Hackerrank Java Abstract Class #76

Closed biryu2205 closed 6 years ago

biryu2205 commented 7 years ago
import java.util.Scanner;

abstract class Book {
  String title;

  abstract void setTitle(String s);

  String getTitle() {
    return title;
  }
}

class MyBook extends Book {
  void setTitle(String s) {
    title = s;
  }
}

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String title = sc.nextLine();
    MyBook new_novel = new MyBook();
    new_novel.setTitle(title);
    System.out.println("The title is: " + new_novel.getTitle());
    sc.close();
  }
}