JSFiddle - React, Tailwind, and code Playground

by bhupendra negi

JavaScript

class Car {
  constructor(make) {
    this.make = make;
    this.speed = 40;
  }
  getSpeed() {
    console.log(`The car ${this.make} goes at ${this.speed} kmph `);
  }
}

class RaceCar extends Car {
  constructor(make, speed) {
    super(make);
    this.TopSpeed = speed;
  }
  goFast() {
    this.speed = this.TopSpeed;
  }
}

let car = new RaceCar("ferrari", 400);
car.getSpeed();
car.goFast();
console.log(car);
car.getSpeed();