声明类
class Dog {
name:string;
age:number;
constructor(name:string,age:number) {
console.log(this);
this.name =name;
this.age =age
}
}
继承
class Animal {
name:string;
age:number;
constructor(name:string,age:number) {
this.name =name;
this.age =age
}
sayHello(){
console.log(`${this.name}在叫!`);
}
}
class Dogs extends Animal{
constructor(name:string,age:number){
super(name,age)
this.age=age
}
run(){
console.log('dog is running!');
}
sayHello(){
super.sayHello()
}
}
抽象类
abstract class people{
name:string;
constructor(name:string) {
this.name=name
}
abstract sayHello():void
}