Create a static integer field that keeps a count across all instances(objects) of a class. Create 3 or 4 object in derived class and then check total instances.
using System;
static class Program
{
static void Main(string[] args)
{
Count a = new Count();
Count b = new Count();
Count c = new Count();
Console.WriteLine(Count.count);
Count d = new Count();
Console.WriteLine(Count.count);
}
}
public class Count
{
public static int count;
public Count()
{
count++;
}
}
Comments
Leave a comment