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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Q178742
{
class Program
{
class Point {
private int x;
private int y;
public static int numberCreatedInstances=0;
public Point(int x,int y)
{
this.x = x;
this.y = y;
numberCreatedInstances++;
}
}
static void Main(string[] args)
{
Point p1 = new Point(4,6);
Console.WriteLine("Point number {0}", Point.numberCreatedInstances);
Point p2 = new Point(62,8);
Console.WriteLine("Point number {0}", Point.numberCreatedInstances);
Point p3 = new Point(2, 48);
Console.WriteLine("Point number {0}", Point.numberCreatedInstances);
Console.ReadLine();
}
}
}
Comments
Leave a comment