テレスコーピング・コンストラクタのサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NutritionFacts { | |
private final int servingSize; // 必須 | |
private final int servings; // 必須 | |
private final int calories; // オプション | |
private final int fat; // オプション | |
private final int sodium; // オプション | |
private final int carbohydrate; // オプション | |
public NutritionFacts(int servingSize, int servings) { | |
this(servingSize, servings, 0); | |
} | |
public NutritionFacts(int servingSize, int servings, int calories) { | |
this(servingSize, servings, calories, 0); | |
} | |
public NutritionFacts(int servingSize, int servings, int calories, int fat) { | |
this(servingSize, servings, calories, fat, 0); | |
} | |
public NutritionFacts(int servingSize, int servings, int calories, int fat, int sodium) { | |
this(servingSize, servings, calories, fat, sodium, 0); | |
} | |
public NutritionFacts(int servingSize, int servings, int calories, int fat, int sodium, int carbohydrate) { | |
this.servingSize = servingSize; | |
this.servings = servings; | |
this.calories = calories; | |
this.fat = fat; | |
this.sodium = sodium; | |
this.carbohydrate = carbohydrate; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment