TypeScript Abstract Class

In object oriented, abstract classes are base classes and cannot be instantiated directly. Abstract classes can have abstract and non-abstract methods. Methods that are marked as abstract do not have implementation and must be implemented by derived classes or sub classes. Abstract classes and methods can be created using abstract keyword within the abstract class.

Unlike interface:
An abstract class can give implementation details for its members.
An abstract class allows to marks its members methods as private and protected.

TypeScript Getter and Setter Property Example

Try it Yourself

In the above example, a new abstract class classA is created. This abstract class has declared one method printAbstract using abstract keyword. That means, this method must be implemented by the derived class. Here, class classB derived from classA and implementing printAbstract abstract method of base class. Also above example demonstrates, when creating object of abstract class error will be resulting.