-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3-14(Class).html
86 lines (71 loc) · 2.45 KB
/
3-14(Class).html
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<html>
<head>
<title>클래스</title>
</head>
<body>
<script>
// 클래스 : 객체를 생성하기 위한 틀, 설계도
class Car {
constructor(modelName, modelYear, type, price) {
this.modelName = modelName;
this.modelYear = modelYear;
this.type = type;
this.price = price;
} // 생성자
getModelName() {
return this.modelName;
}
getModelYear() {
return this.modelYear;
}
getType() {
return this.type;
}
getPrice() {
return this.price;
}
setPrice(price) {
this.price = price;
}
}
// let car1 = new Car("아이오닉", "2021", "E", 4000); // 클래스라는 car가 객체로 생성
// console.log(car1.getModelName());
// console.log(car1.getModelYear());
// console.log(car1.getType());
// console.log(car1.getPrice());
// car1.setPrice(3000);
// console.log(car1.getPrice());
// console.log("--------------------------------------------");
// let car2 = new Car("제네시스", "2023", "G", 8500);
// console.log(car2.getModelName());
// console.log(car2.getModelYear());
// console.log(car2.getType());
// console.log(car2.getPrice());
class ElectronicCar extends Car {
constructor(modelName, modelYear, price, time) {
super(modelName, modelYear, "E", price);
this.time = time;
}
getTime() {
return this.time;
}
setTime(time) {
this.time = time;
}
}
let eleCar1 = new ElectronicCar("아이오닉2", "2022", 4800);
console.log(eleCar1.getModelName());
console.log(eleCar1.getModelYear());
console.log(eleCar1.getType());
console.log(eleCar1.getPrice());
console.log("--------------------------------------------");
let eleCar2 = new ElectronicCar("아이오닉3", "2024", 5500, 60);
console.log(eleCar2.getModelName());
console.log(eleCar2.getModelYear());
console.log(eleCar2.getType());
console.log(eleCar2.getPrice());
eleCar2.setTime(30);
console.log(eleCar2.getTime());
</script>
</body>
</html>