2.class与继承

// 父类
class People{
    constructor(name){
        this.name = name;
    }
    eat(){
        console.log(`姓名 ${this.name} eat something  `)
    }
}
// 子类
class Student extends People {
    constructor(name, number) {
        super(name);
        this.number = number;
        
    }
    sayHi() {
        console.log(`姓名 ${this.name}  ,  学号  ${this.number}  `)
    }

}
const aaa = new Student('lisi',100)
console.log(aaa.name)
console.log(aaa.number)
aaa.sayHi()
aaa.eat()

  

猜你喜欢

转载自www.cnblogs.com/chenlw/p/12525812.html