// 抽象类不能创建实例
(function () {
abstract class Animal {
name: string;
constructor(name: string) {
this.name = name;
}
// 抽象方法只能且必须在子类进行重写
abstract sayHi(): void;
}
class Dog extends Animal {
sayHi() {
console.log("hihihi");
}
}
class Cat extends Animal {
constructor(name: string) {
super(name);
}
sayHi() {
console.log("hi");
}
}
})();