namespace FruitBasket
{
using System;
/// <summary>
/// Abstract Fruit class (using as basket)
/// </summary>
public abstract class Fruit
{
/// <summary>
/// Number of fruits static property
/// </summary>
public static int NumberOfFruits { get; protected set; }
}
/// <summary>
/// Apple class derived from Fruit
/// <inheritdoc cref="Fruit"/>
/// </summary>
public class Apple : Fruit
{
/// <summary>
/// Initializes a new instance of the <see cref="Apple"/> class.
/// </summary>
public Apple()
{
NumberOfApples++; // increase number of apples
NumberOfFruits++; // increase number of fruits in basket
}
/// <summary>
/// Number of apples static property
/// </summary>
public static int NumberOfApples { get; protected set; }
}
/// <summary>
/// Mango class derived from Fruit
/// <inheritdoc cref="Fruit"/>
/// </summary>
public class Mango : Fruit
{
/// <summary>
/// Initializes a new instance of the <see cref="Mango"/> class.
/// </summary>
public Mango()
{
NumberOfMangoes++; // increase number of mangoes
NumberOfFruits++; // increase number of fruits in basket
}
/// <summary>
/// Number of mangoes static property
/// </summary>
public static int NumberOfMangoes { get; protected set; }
}
public class Program
{
public static void Main(string[] args)
{
var apple = new Apple();
var apple2 = new Apple();
var apple3 = new Apple();
var mango = new Mango();
var mango2 = new Mango();
var mango3 = new Mango();
var mango4 = new Mango();
var mango5 = new Mango();
Console.WriteLine($"Total number of apples in the basket - {Apple.NumberOfApples}");
Console.WriteLine($"Total number of mangoes in the basket - {Mango.NumberOfMangoes}");
Console.WriteLine($"Total number of fruits in the basket - {Fruit.NumberOfFruits}");
}
}
}
Comments
Leave a comment