Skip to content

Latest commit

 

History

History
26 lines (21 loc) · 407 Bytes

File metadata and controls

26 lines (21 loc) · 407 Bytes

Section 7.3: Basic Inheritance

class Car {
  public position: number = 25;
  protected speed: number = 42;

  move() {
    this.position += this.speed;
    console.log(this.position);
  }
}
  
class SelfDrivingCar extends Car {
  move() {
    //super.move();
    console.log('Hi Morol');
  }
}

let myCar = new Car();
myCar.move(); // 67

myCar = new SelfDrivingCar();
myCar.move(); // Hi Morol