W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
interface Shape { getArea: () => number; } class Rectangle implements Shape { public constructor(protected readonly width: number, protected readonly height: number) {} public getArea(): number { return this.width * this.height; } } class Square extends Rectangle { public constructor(width: number) { super(width, width); } // `getArea` 方法从 Rectangle 类继承而来 } const mySq = new Square(20); console.log(mySq.getArea());