-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment2p2.java
More file actions
49 lines (41 loc) · 1.25 KB
/
Assignment2p2.java
File metadata and controls
49 lines (41 loc) · 1.25 KB
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
class Book {
String title;
String author;
double price;
public Book(String title, String author, double price) {
this.title = title;
this.author = author;
this.price = price;
}
public void displayDetails() {
System.out.println("Title: " + title);
System.out.println("Author: " + author);
System.out.println("Price: " + price);
}
}
class Fiction extends Book {
public Fiction(String title, String author, double price) {
super(title, author, price);
}
public void displayDetails() {
System.out.println("Fiction Book Details:");
super.displayDetails();
}
}
class NonFiction extends Book {
public NonFiction(String title, String author, double price) {
super(title, author, price);
}
public void displayDetails() {
System.out.println("Non-Fiction Book Details:");
super.displayDetails();
}
}
public class Assignment2p2 {
public static void main(String[] args) {
Fiction fictionBook = new Fiction("Harry Potter", "J.K. Rowling", 500);
NonFiction nonFictionBook = new NonFiction("Sapiens", "Yuval Noah Harari", 700);
fictionBook.displayDetails();
nonFictionBook.displayDetails();
}
}