小编eri*_*ris的帖子

参数为最大值的Java构造函数

从Java开始,我希望创建时构造函数中的一个参数不超过某个值。举个例子 :

public class Vehicule {
    protected String immat;
    protected int poidsVide;
    protected int charge;
    protected int chargeMax;

    Vehicule(String immat, int poidsVide, int charge) {
        this.immat = immat;
        this.poidsVide = poidsVide;
        this.charge = charge;
        this.chargeMax = 10000;
   }
}
Run Code Online (Sandbox Code Playgroud)

我不希望任何带有“ charge”优于“ chargeMAx”实例的对象该怎么办?尝试了几种选择,到目前为止没有用。

谢谢你的帮助。

java constructor

0
推荐指数
1
解决办法
34
查看次数

标签 统计

constructor ×1

java ×1