Difference between extends and implements
Features |
extends |
Implements |
---|---|---|
Inheritance |
Extends is used for class inheritance. It allows a class to inherit properties and methods from another class. |
Implements is used for interface implementation. It enables a class to provide specific implementations for the methods defined in an interface. |
Multiple Inheritance |
A class can extend only one class |
A class can implement multiple interfaces |
Implementation of Methods |
No direct implementation of methods. |
Requires the class to provide concrete implementations for all methods declared in the interface. |
Code Reusability |
Promotes code reusability |
Promotes code reusability and abstraction through interfaces. |
Abstract Classes |
Can extend abstract classes |
Cannot extend abstract classes but can implement abstract methods. |
What’s the Difference Between ‘extends’ and ‘implements’ in TypeScript ?
In TypeScript, extends
and implements
are primarily used to define relationships between types and classes. In this article, we will learn the difference between ‘extends’ and ‘implements’ in TypeScript.