Tea (Tea), coffee (Coffee), and beer (Beer) all belong to a kind of beverage (Beverage). They all have characteristics such as brand (brand), type (typeName), place of origin (place), and price (price). they all

Tea (Tea), coffee (Coffee), and beer (Beer) all belong to a kind of beverage (Beverage). They all have characteristics such as brand (brand), type (typeName), place of origin (place), and price (price). They all have certain production methods (make). However, different beverages are made in completely different ways. .
Please implement the Beverage and Coffee classes in code.

//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);
    }
}

Guess you like

Origin blog.csdn.net/zezeaichirou/article/details/130172216