代码
提交代码
class Animal { public name:string constructor(name: string) { this.name = name } move(distance: number = 0) { console.log(`${this.name} moved ${distance}m.`) } } class Dog extends Animal { constructor(name: string) { // 调用父类的构造函数 super(name) } move(distance = 10) { console.log('bark...') // 执行父类的方法 super.move(distance) } } const dog: Animal = new Dog('Coco') dog.move() // Coco moved 10m.
运行结果