상속
class Vehicle{
constructor(acceleration = 1){
this.speed = 0
this.acceleration = 1
}
accelerate(){
this.speed += this.acceleration
}
decelerate(){
if(this.speed<0){
console.log('정지');
return
}
this.speed -= this.acceleration
}
}
class Bicycle extends Vehicle {
constructor(price = 100, accleration){
super(acceleration)
this.price = price
this.wheel = 2
}
}
const bicycle = new Bicycle(300, 2);
class Car extends Bicycle{
constructor(license, price, acceleration){
super(price, acceleration)
this.license = license
this.wheel = 4
}
accelerate(){
if(!this.license){
console.error('무면허')
}
this.speed += this.acceleration
console.log('가속!')
}
}
const carA = new Car(true, 7000, 10)
const carB = new Car(false, 7000, 10)