Multiple Interface Implementation C# with Example



Multiple Interface Implementation C# with Example

 using System;

namespace CSharpInterface
{
	interface IShape
	{
		double Area();
	}
	
	interface IDisplay
	{
		void Display();
	}
	
    class Shape
    {
        public double dim1, dim2;

        public Shape(double dimension1, double dimension2)
        {
            dim1 = dimension1;
            dim2 = dimension2;
        }
    }
	
    class Rectangle : Shape, IShape, IDisplay
    {
        public Rectangle(double dimension1, double dimension2) : base(dimension1, dimension2) { }

        public double Area()
        {
            return dim1 * dim2;
        }
		
		public void Display()
		{
			Console.WriteLine("Area of Rectangle : " + Area());
		}
    }

    class Triangle : Shape, IShape, IDisplay
    {
        public Triangle(double dimension1, double dimension2) : base(dimension1, dimension2) { }

        public double Area()
        {
            return dim1 * dim2 / 2;
        }
		
		public void Display()
		{
			Console.WriteLine("Area of Triangle : " + Area());
		}
    }

    class MultipleInterfaceImplementation
    {
        public static void Main(string[] args)
        {
            Rectangle newRectangle = new Rectangle(6, 7);
            Triangle newTriangle = new Triangle(12, 23);

            newRectangle.Display();
            newTriangle.Display();
        }
    }
}
 

0 Comment's

Comment Form

Submit Comment