-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path상속.js
More file actions
36 lines (28 loc) · 777 Bytes
/
상속.js
File metadata and controls
36 lines (28 loc) · 777 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
// Vehicle을 만들어서 다른 것들에 상속
class Vehicle{
constructor(name, wheel){
this.name = name
this.wheel = wheel
}
}
const myVehicle = new Vehicle('운송수단', 2)
console.log(myVehicle)
class Bicycle extends Vehicle{ // extends : 확장(상속)
constructor(name, wheel){
super(name, wheel)
}
}
const myBicycle = new Bicycle('삼천리', 2)
const daughtersBicycle = new Bicycle('세발', 3)
console.log(myBicycle)
console.log(daughtersBicycle)
class Car extends Vehicle{
constructor(name, wheel, license){ // license 추가, 확장
super(name, wheel)
this.license = license
}
}
const myCar = new Car('벤츠', 4, true)
const daughtersCar = new Car('포르쉐', 4, false)
console.log(myCar)
console.log(daughtersCar)