js 继承

//父类
class Person{
    constructor(name) {
        this.name = name
    }
    eat(){
        console.log(`${this.name} eat something`)
    }
}

//子类
class Student extends Person{
    constructor(name,number) {
        super(name);
        this.number = number
    }
    sayHI(){
        console.log(`姓名 ${this.name} 学号 ${this.number} `)
    }
}

//实列
const std = new Student('周瑜',333)
std.sayHI()
std.eat()

 

//父类
class Person{
constructor(name) {
this.name = name
}
eat(){
console.log(`${this.name} eat something`)
}
}

//子类
class Student extends Person{
constructor(name,number) {
super(name);
this.number = number
}
sayHI(){
console.log(`姓名 ${this.name} 学号 ${this.number} `)
}
}

//实列
const std = new Student('周瑜',333)
std.sayHI()
std.eat()
上一篇:Python笔记-5_下


下一篇:TS之静态属性、静态方法 & 抽象类、抽象方法