如何在一个类中实现多个接口? [英] How do I implement multiple interfaces in a class?
本文介绍了如何在一个类中实现多个接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在泛型类中实现这两个接口.我该怎么做?
I want to implement both the interfaces in the generic class. How do I do that?
interface first {
name: string,
age: number
}
interface second {
product: string,
available: boolean,
amount: number
}
class generics <T>{
}
推荐答案
使用 ,
来分隔要实现的接口.这给出了以下类声明:
Use a ,
to separate the interfaces you want to implement. That gives the following class declaration :
class generics <T> implements first, second
完整代码如下:
interface first {
name: string,
age: number
}
interface second {
product: string,
available: boolean,
amount: number
}
class generics <T> implements first, second {
name: string;
age: number;
product: string;
available: boolean;
amount: number;
}
这篇关于如何在一个类中实现多个接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文