We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Monday, June 22, 2015

Write a program to create ‘ConstOverLoad’ class with a constructor which takes a, b Integer values as arguments and assigns as Height, Width values for Rectangle. Overload the Constructor method with size value as an argument and assign as Height & Width value for Square. Show the results on a Console application.

class Program
    {
        public class ConstOverLoad
        {
            int Height, Width;
            public ConstOverLoad(int a, int b)
            {
                Height = a;
                Width = b;
            }
            public ConstOverLoad(int x)
            {
                Height = x;
                Width = x;
            }
            public void Show()
            {
                Console.WriteLine("Height is:" + Height);
                Console.WriteLine();
                Console.WriteLine("Width is" + Width);
            }           
        }
        static void Main(string[] args)
        {

            ConstOverLoad c = new ConstOverLoad(50, 80);
            Console.WriteLine("Result for Rectangel.. \n");
            c.Show();
            Console.WriteLine();
            ConstOverLoad c1 = new ConstOverLoad(100);
            Console.WriteLine("Result for Square. ");
            c1.Show();
            Console.ReadLine();
        }

    }
OUTPUT:

No comments: