...
/Solution Review: Calling a Constructor from a Constructor
Solution Review: Calling a Constructor from a Constructor
This review provides insight to the solution of the 'Calling a Constructor from a Constructor' challenge.
We'll cover the following...
Solution
Press + to interact
class VendingMachine {// Private Fieldsprivate string _count;private string _capacity;private string _moneyCollected;// Default Constructorpublic VendingMachine() {this._count = "";this._capacity = "";this._moneyCollected = "";}// Parameterized Constructor 1public VendingMachine(string count, string capacity) {this._count = count;this._capacity = capacity;}// Parameterized Constructor 2public VendingMachine(string count, string capacity, string money): this(count, capacity){this._moneyCollected = money;}// Method to return vending machine detailspublic string GetDetails() {return this._count + ", " + this._capacity + ", " + this._moneyCollected;}}class Demo {public static void Main(string[] args) {VendingMachine vendy = new VendingMachine("Count: 45", "Capacity: 50", "Money Collected: 440$");Console.WriteLine(vendy.GetDetails());}}