2.11类中的访问类型与构造器

// private protected,public 访问类型
// public 允许在类里面或者外面调用
// private 允许在类内被使用
// protected 允许在类内以及继承的子类中使用
class Person3 {
  protected age: number;
  public name: string;
  private sayHi() {
    this.name;
  }
}
//constructor 构造器
class Person4 {
  // public name: string;
  constructor(public name: string) {
    this.name = name;
  }
  // 简化写法
  // constructor (public name: string){}
}
const person4 = new Person4("dell");
class Teacher4 extends Person4 {
  constructor(public age: number) {
    super("dell");
    //父类和子类都有构造器,那么子类需要继承,切需要按要求传参数
  }
}
原文地址:https://www.cnblogs.com/sinceForever/p/14843304.html