Answer to Question #178961 in C# for Hassan Raza

Question #178961

 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-07T00:19:13-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Q178961
{
    class Program
    {

        class Point {
            private int x;
            private int y;
            public static int counter=0;


            public Point() {
                counter++;
            }
            public Point(int x,int y)
            {
                this.x = x;
                this.y = y;
                counter++;
            }


            public int X
            {
                get { return x; }
                set { x = value; }
            }
            


            public int Y
            {
                get { return y; }
                set { y = value; }
            }
        }
        static void Main(string[] args)
        {
            Point Point1 = new Point();
            Console.WriteLine("The number of created instances of type Point: {0}", Point.counter);
            Point Point2 = new Point(5,6);
            Console.WriteLine("The number of created instances of type Point: {0}", Point.counter);
            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