Abstract Classes

Abstract classes in TypeScript serve as a base class and cannot be instantiated. They can, however, be extended. Abstract classes can contain real implementation for some methods, but they can also have abstract methods, which don't have an implementation in the abstract class and must be implemented by any concrete (non-abstract) subclass.


abstract class Animal {
    abstract makeSound(): void;

    move(): void {

class Dog extends Animal {
    makeSound() {

const myDog = new Dog();
myDog.makeSound();  // Outputs: Bark!
myDog.move();       // Outputs: Moving...

Here, the Animal class has an abstract method makeSound, which is then implemented by the Dog subclass.


Extend the abstract class Shape and create two classes: Circle and Rectangle. Implement the abstract area method in both classes to return the area of the shape.

Copyright © learn-ts.org. Read our Terms of Use and Privacy Policy