📜  如何在抽象类中重载构造函数 - 无论代码示例

📅  最后修改于: 2022-03-11 15:00:05.953000             🧑  作者: Mango

代码示例1
abstract class Product { 
    int multiplyBy;
    public Product( int multiplyBy ) {
        this.multiplyBy = multiplyBy;
    }

    public int mutiply(int val) {
       return multiplyBy * val;
    }
}

class TimesTwo extends Product {
    public TimesTwo() {
        super(2);
    }
}

class TimesWhat extends Product {
    public TimesWhat(int what) {
        super(what);
    }
}