面试题答案
一键面试class Animal {
protected name: string;
constructor(name: string) {
this.name = name;
}
speak() {
console.log(`The animal ${this.name} makes a sound.`);
}
}
class Dog extends Animal {
constructor(name: string) {
super(name);
}
bark() {
console.log(`Dog ${this.name} is barking.`);
this.speak();
}
}
const myDog = new Dog('Buddy');
myDog.bark();