Saturday 10 March 2012

Interface in C#


//Interface Introduction
using System;

interface Shape// Declaring interface
{
void Area();
}

class Rectangle:Shape
{
public void Area()
{
Console.WriteLine("\nArea Of Rectangle Is Length*Breath");
}
}

class Square:Shape
{
public void Area()
{
Console.WriteLine("\nArea Of Square Is Side*Side");
}
}

class Circle:Shape
{
public void Area()
{
Console.WriteLine("\nArea Of Circle Is R*R*Pi");
}
}

class Program
{
static void Main()
{
Shape shapeObj;

shapeObj=new Rectangle();
shapeObj.Area();

shapeObj=new Square();
shapeObj.Area();

shapeObj=new Circle();
shapeObj.Area();
}
}

No comments:

Post a Comment