// public 定义类的变量默认就是公共的,继承的子类可以通过this来访问// private 定义类的私有属性,只能在内部访问class Person {private name: string = ""getName() {return this.name}setName(newName) {this.name = newName}}const p = new Person()console.log(p.getName())p.setName('xbj')// protected: 在类的内部和子类中可以访问,在外面就访问不到了class Person {protected name: stringconstructor(name: string) {this.name = name}}class Student extends Person {constructor(name: string, age: number){super(name)}getName() {return this.name}}
