面试题答案
一键面试abstract class Shape {
abstract getArea(): number;
}
class Circle extends Shape {
private radius: number;
constructor(radius: number) {
super();
this.radius = radius;
}
getArea(): number {
return Math.PI * this.radius * this.radius;
}
}
class Rectangle extends Shape {
private length: number;
private width: number;
constructor(length: number, width: number) {
super();
this.length = length;
this.width = width;
}
getArea(): number {
return this.length * this.width;
}
}