TypeScript 里的 override
export class Animal {
public say():void{
console.log("I am a Animal");
}
}
export class Dog extends Animal {
public override say():void{
console.log("I am a Dog");
}
}
let animal: Animal = new Dog();
animal.say(); // output: I am a Dog
let dog: Dog = new Dog();
dog.say();// output: I am a Dog
- 当子类方法的名称、参数、返回值都相同时,则视为覆盖基类的方法,
override
关键字可以省略