面试题答案
一键面试interface BaseInterface {
name: string;
}
interface DerivedInterface extends BaseInterface {
age: number;
}
class MyClass implements DerivedInterface {
name: string;
age: number;
constructor(name: string, age: number) {
this.name = name;
this.age = age;
}
printProperties() {
console.log(`Name: ${this.name}, Age: ${this.age}`);
}
}
你可以通过以下方式测试这个类:
const myObject = new MyClass('John', 30);
myObject.printProperties();