class PersonA {
name:string
age1:number
sub:boolean
constructor(name:string, age1:number, sub:boolean) {
this.name = name
this.age1 = age1
this.sub = sub
}
}
new PersonA('测试', 12, true)
//类修饰符 public private protected
//public内部外部都能访问
//private 私有变量只能在内部使用
//protected 内部和子类中访问
//static 静态属性
class PersonB {
public name:string
private age1:number
protected sub:boolean
static aaa:string = '123static'
constructor(name:string, age1:number, sub:boolean) {
this.name = name
this.age1 = age1
this.sub = sub
}
static run() {
return this.aaa //只能访问static 不能访问public private protected
}
static test() {
return this.run() //可以调取内部方法
}
}
class ManA extends PersonB {
constructor() {
super('测试1', 112, false)
//子类可以访问到protected变量
}
}
console.log(PersonB.aaa, PersonB.run()) //可以直接访问
let pb =new PersonB('测试1', 112, false)
interface PersonC {
run(type:boolean):boolean
}
interface H {
set():void
}
class HX {
params:string
constructor(params) {
this.params = params
}
}
class ManC extends HX implements PersonC,H {
run(type:boolean):boolean {
return type
}
set() {
}
}