Create a class Point, which defines a point on the coordinate plane. Implement a count of the number of created instances of type Point
using System;
namespace Test
{
public class Point
{
private static int _counter = 0;
private readonly int _x;
private readonly int _y;
public Point(int x, int y)
{
_x = x;
_y = y;
++_counter;
}
public int GetX() { return _x; }
public int GetY() { return _y; }
public static int GetCounter() { return _counter; }
}
class PointTest
{
static void Main()
{
Point p1 = new Point(0, 0);
Console.WriteLine("Counter value: {0}", Point.GetCounter());
Point p2 = new Point(1, 1);
Console.WriteLine("Counter value: {0}", Point.GetCounter());
}
}
}
Comments
Leave a comment