【TypeScript】七、抽象类
  1. 抽象类被继承使用,抽象类中abstract修饰的方法不能有实现,实现抽象类的类需要实现抽象类中所有抽象方法
abstract class A {
    name: string
    constructor(name: string) {
        this.name = name
    }

    abstract run(time: number, where: string): string
}

class B extends A {
    run(time: number, where: string): string {
        return `${this.name}在${where}跑了${time.toString()}分钟`
    }
}
let b = new B("hamu")
console.log(b.run(10, "白云区"))

posted on 2022-07-05 17:33  仓鼠不爱吃辣条  阅读(30)  评论(0)    收藏  举报

页尾

页尾

页尾

页尾

页尾

页尾

页尾