-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritance.js
More file actions
46 lines (40 loc) · 912 Bytes
/
inheritance.js
File metadata and controls
46 lines (40 loc) · 912 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
41
42
43
44
45
46
class SmartDevice {
constructor(name, price) {
this.name = name;
this.price = price;
}
charging() {
console.log("I am eating electrons");
}
}
class Phone extends SmartDevice {
constructor(name, price, camera) {
super(name, price);
this.camera = camera;
}
sendSms() {
console.log("I am sending text");
}
}
class Watch extends SmartDevice {
constructor(name, price, distance) {
super(name, price);
this.distance = distance;
}
}
class Tablet extends SmartDevice {
constructor(name, price, WiFi) {
super(name, price);
this.WiFi = WiFi;
}
}
const samsung = new Phone("Samsung", 60000, "32mp");
samsung.charging();
samsung.sendSms();
console.log(samsung);
const appleWatch = new Watch("Watch 6", 32000, "15km");
appleWatch.charging();
console.log(appleWatch);
const iPad = new Tablet("iPad Pro", "70000", true);
iPad.charging();
console.log(iPad);