乐闻世界logo
搜索文章和话题

Can a class implement multiple interfaces in TypeScript?

2月7日 12:40

Yes, a class in TypeScript can implement multiple interfaces. This allows the class to implement various behaviors and functionalities, while interfaces define the specifications for these behaviors. When implementing multiple interfaces, you need to ensure that the class implements all properties and methods defined in the interfaces. For example:

typescript
interface ICar { drive(): void; } interface IAirplane { fly(): void; } class FlyingCar implements ICar, IAirplane { drive() { console.log("Driving on the road."); } fly() { console.log("Flying in the sky."); } }
标签:TypeScript