react18-学习笔记12-类class

class Animal{
   protected name: string;
   static age=18
    constructor (name:string){
        this.name=name
    }
    run(){
        return `${this.name}`
    }
}
const snake=new Animal("geyao")
console.log(Animal.age)
class Dog extends Animal{
    bark(){
        return `${this.name}`
    }
}
const dog=new Dog("geyao")

class Cat extends Animal{
    bark(){
        return `${this.name}`
    }
}
const cat=new Cat("geyao")

posted @ 2022-08-26 20:35  前端导师歌谣  阅读(31)  评论(0)    收藏  举报