// public
// protected
// private
class Person1{
public sex1:string
protected name1:string
private age1:number
public constructor(sex1:string,name1:string,age1:number){
this.sex1=sex1
this.name1=name1
this.age1=age1
}
public say(){
console.log('你好')
}
protected sayLove(){
console.log('我爱你')
}
}
let Bob:Person1 = new Person1('女','迪丽热巴',22)
console.log(Bob.sex1)
console.log(Bob.name1) //有出错提示
console.log(Bob.age1) //有出错提示
Bob.say()
Bob.sayLove() //有出错提示
// 只读修饰符readonly
class Man {
public readonly sex:string='男'
}
let man:Man = new Man()
man.sex = '女' //有出错提示