-
Notifications
You must be signed in to change notification settings - Fork 0
/
day13_abtract_classes.java
50 lines (43 loc) · 1.09 KB
/
day13_abtract_classes.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Provided by Hacker Rank
import java.util.*;
abstract class Book
{
String title;
String author;
Book(String t,String a){
title=t;
author=a;
}
abstract void display();
}
// Only this block below is my work
//Write MyBook Class
//** Subclass of Book **/
class MyBook extends Book {
/** Parameterized Constructor **/
private int price; // declare price as a private integer
MyBook(String title, String author, int price){
super(title, author);
this.price = price;
}
/** Abstract method implementation
* print out myBook info **/
void display(){
System.out.println("Title: " +title);
System.out.println("Author: " +author);
System.out.println("Price: " +price);
}
}
// Below code is provided by Hacker Rank
public class Solution
{
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
String title=sc.nextLine();
String author=sc.nextLine();
int price=sc.nextInt();
Book new_novel=new MyBook(title,author,price);
new_novel.display();
}
}