Basic Inheritance

suggest change
class Car {
    public position: number = 0;
    protected speed: number = 42;
    
    move() {
        this.position += this.speed;
    }
}  

class SelfDrivingCar extends Car {

    move() {
        // start moving around :-)
        super.move();
        super.move();
    }
}

This examples shows how to create a very simple subclass of the Car class using the extends keyword. The SelfDrivingCar class overrides the move() method and uses the base class implemention using super.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents