-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram-7.js
More file actions
30 lines (25 loc) · 1.06 KB
/
program-7.js
File metadata and controls
30 lines (25 loc) · 1.06 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
// Write a JavaScript program that creates a class `Book` with properties for title, author, and publication year. Include a method to display book details. Create a subclass called 'Ebook' that inherits from the 'Book' class and includes an additional property for book price. Override the display method to include the book price. Create an instance of the 'Ebook' class and display its details.
class Book {
constructor(title, author, publicationYear) {
this.title = title;
this.author = author;
this.publicationYear = publicationYear;
}
displayDetails() {
console.log(`Title: ${this.title}`);
console.log(`Author: ${this.author}`);
console.log(`Publication Year: ${this.publicationYear}`);
}
}
class Ebook extends Book {
constructor(title, author, publicationYear, price) {
super(title, author, publicationYear);
this.price = price;
}
displayDetails() {
super.displayDetails();
console.log(`Price: $${this.price}`);
}
}
const ebookInstance = new Ebook("Sample Ebook", "John Doe", 2023, 9.99);
ebookInstance.displayDetails();