interface 接口
接口:规定类必须具有的功能
interface A{
//接口没有构造函数
num1:number
a1():void;
//接口中的方法不能有方法体
}
接口不能被实例化
let a:A=new A()
实现类:必须有接口中的属性,必须重写接口中的方法
lass B implements A{
num1:number
a1(): void{
console.log('重写的接口的函数')
}
constructor(num1:number){
this.num1=num1
}
}
let bb:B=new B(1);
bb.a1()
interface Usb{
in():void;
outs():void;
}
class Fs{
type:string
ts(){
console.log('调节风扇速度')
}
constructor(type:string){
this.type=type
}
in():void{
console.log('风扇插入usb')
}
outs():void{
console.log('风扇拔出usb')
}
}
let fss:Fs=new Fs('海尔')
fss.in()
fss.ts()
fss.outs()