class Point {
private x: number;
private y: number;
constructor(x: number, y: number) {
this.x = x;
this.y = y;
}
public distance(otherPoint: Point): number {
return Math.sqrt(
Math.pow(this.x - otherPoint.getX(), 2) +
Math.pow(this.y - otherPoint.getY(), 2));
}
public getX() {
return this.x;
}
public getY() {
return this.y;
}
}
class Circle {
private center: Point;
private radius: number;
constructor(center: Point, radius: number) {
this.radius = radius;
this.center = center;
}
public isInside(otherPoint: Point): boolean {
return this.center.distance(otherPoint) < this.radius;
}
}
class Triangle extends Point {
private z: number;
constructor(x:number, y: number, z: number){
super(x, y);
this.z = z;
}
public getZ(){
return this.z
}
public getPerimeter (otherPoint: Triangle): number{
return otherPoint.getX() + otherPoint.getY() + otherPoint.getZ()
}
}
let per = new Triangle(24, 61, 32);
console.log(per);
所以当我尝试编译时它说
private x: number;
^
SyntaxError: Unexpected identifier
一只斗牛犬
噜噜哒
相关分类