-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathAbstractDemo.java
More file actions
40 lines (31 loc) · 807 Bytes
/
AbstractDemo.java
File metadata and controls
40 lines (31 loc) · 807 Bytes
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
import java.util.Scanner;
abstract class Book {
String title;
String author;
Book(String t, String a) {
title = t;
author = a;
}
abstract void display();
}
class MyBook extends Book {
private int price;
MyBook(String t, String a, int p) {
super(t, a);
price = p;
}
@Override
void display() {
System.out.println("Title: " + title + "\nAuthor: " + author + "\nPrice: " + price);
}
}
public class AbstractDemo {
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();
}
}