继承extends 子类继承父类(扩展)
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
say() {
console.log(`my name is ${this.name}, age is ${this.age}`)
}
}
class Student extends People {
public no: number;
protected weight: string;
// 定义private属性
private gf: string;
constructor(name: string, age: number, no: number) {
super(name, age);
this.no = no;
this.gf = 'fe';
this.weight = '60kg'
}
public say() {
super.say();
}
private sayNo() {
console.log(`and my no is ${this.no}`);
}
}
const xiaoming = new Student('xiaoming', 22, 20200201);
// xiaoming.gf(); // error