Sunday, 24 November 2013

C# Constructor Overloading Code----------|||||||

CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleAppoperatoroverloading
{
    public class room
    {
        int length;
        int breadth;
        public room(int x, int y)
        {
            //  Console.WriteLine("\n Enter length");
            // length = int.Parse(Console.ReadLine());
            // Console.WriteLine("\n Enter breadth");
            // breadth = int.Parse(Console.ReadLine());
            length = x;
            breadth = y;

        }

        public room(int z)
        {
            length = breadth = z;
        }
        public int area()
        {
            return (length * breadth);
        }



        public class mytest
        {
            static void Main(string[] args)
            {
                room area1 = new room(10, 10);
                int j = area1.area();
                Console.WriteLine("\n area of rectangle is" + " " + j);
                room area2 = new room(20);
                int k = area2.area();
                Console.WriteLine("\n area of square is " + " " + k);
                Console.ReadKey();
            }
        }

    }
}
OUTPUT:

No comments:

Post a Comment