接口的继承
interface Person {
fname: string;
age: number;
eat():void
}
// 通过extends实现接口的继承
interface WorkerMan extends Person {
profession: string;
yearsOfWork: number;
coding():void
}
// 继承出来的接口,用于约束类
class WorkerPerson implements WorkerMan {
fname: string;
age: number;
profession: string;
yearsOfWork: number;
constructor (f:string, a:number, p:string, y:number) {
this.fname = f;
this.age = a;
this.profession = p;
this.yearsOfWork = y;
}
eat() {
}
coding() {
}
}
类既可以被接口约束,还可继承其他的类
类可与继承其他类,但依然会被接口约束
interface Person {
fname: string;
age: number;
eat():void
}
// 通过extends实现接口的继承
interface WorkerMan extends Person {
profession: string;
yearsOfWork: number;
coding():void
}
// 某个类,即可被接口约束,还可称为超类的子类
class Home {
address:string;
constructor(addre:string) {
this.address = addre;
}
}
// 继承于其他类,还可被接口约束
class WorkerPersonHome extends Home implements WorkerMan {
fname: string;
age: number;
profession: string;
yearsOfWork: number;
constructor (f:string, a:number, p:string, y:number, ad:string) {
super(ad); //
this.fname = f;
this.age = a;
this.profession = p;
this.yearsOfWork = y;
}
eat() {
}
coding() {
}
}