Answer to Question #178742 in C# for muhammad arfan

Question #178742

Create a class Point, which defines a point on the coordinate plane. Implement a count of the number of created instances of type Point.


1
Expert's answer
2021-04-07T01:57:39-0400
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();
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS