茶(Tea)、咖啡(Coffee)、啤酒(Beer),都属于饮品(Beverage)的一种,它们都具有品牌(brand)、类型(typeName)、产地(place)、价格(price)等特征,它们都

茶(Tea)、咖啡(Coffee)、啤酒(Beer),都属于饮品(Beverage)的一种,它们都具有品牌(brand)、类型(typeName)、产地(place)、价格(price)等特征,它们都有一定的制作方法(make)。但是,不同的饮品,制作的方法却完全不一样。。
请用代码实现Beverage类和Coffee类。

//Beverage类
class Beverage {
    constructor(brand, typeName, place, price) {
        this.brand = brand;
        this.typeName = typeName;
        this.place = place;
        this.price = price;
    }

    make() {
        console.log("制作" + this.typeName);
    }
}

//Coffee类继承自Beverage类
class Coffee extends Beverage {
    constructor(brand, place, price) {
        super(brand, "咖啡", place, price);
    }

    make() {
        console.log("研磨咖啡豆,冲泡" + this.typeName);
    }
}

猜你喜欢

转载自blog.csdn.net/zezeaichirou/article/details/130172216