You must use the constructor to construct multiple constructor parameters.
General overlapping constructor mode:
Public class NutritionFacts {private final int one; private final int two; private final int three; public NutritionFacts (int one, int two, int three) {this. one = one; this. two = two;} public NutritionFacts (int one) {this (one, 0);} public NutritionFacts (int one, int two) {this (one, two, 0) ;}} // when calling the page, the value of NutritionFacts nt = new NutritionFacts (, 0); // disadvantage: overlapping constructor mode. When there are many parameters, difficult to write and read;
Improvement: Builder mode:
Public class NutritionFacts {private final int one; private final int two; private final int three; private NutritionFacts (Bulider builder) {one = builder. one; two = builder. two; three = builder. three;} public static class Builder {private String name; private int one = 0; private int two = 0; private int three = 0; public Builder (String name) {this. name = name;} public Builder one (int value) {one = value; reture this;} public Builder two (int value) {two = value; reture this ;} public Builder two (int value) {two = value; reture this;} // call, and finally instantiate the external class public NutritionFacts build () {return new NutritionFacts (this );}}}