xiaoing.com©

开花即结果 提问即答案

定义一个MONKEY类继承ANIMAL
原始问题:

定义一个MONKEY类继承ANIMAL

class Animal {
constructor(name) {

this.name = name;

}

eat() {

console.log(`${this.name} is eating`);

}

sleep() {

console.log(`${this.name} is sleeping`);

}

move() {

console.log(`${this.name} is moving`);    

} //定义一个Animal类,有名字、吃、睡、动四个方法。

class Monkey extends Animal{ //定义一个Monkey类,继承Animal类。

 constructor(name){                       //构造函数传入的参数是名字。       
    super(name);                         //调用Animal的构造函数,传入参数。   

 climb(){                                //定义新的方法climb(),表明猴子会攀岩。                                               console.log(`${this.name} can climb trees!`);               }                  }
定义一个MONKEY类继承ANIMAL
https://www.xiaoing.com/zhidao/11297.html
AI / 模型iFLYTEK
时间 / DATEApril 16, 2023, 2:14 PM
语言zh-CN
IP / 区域海南 海口

Prev:go cfb1算法