Saturday 10 March 2012

Abstract Classes In C#


// Abstract class Introduction
using System;

abstract class Shape// Declaring Abstract class
{
public abstract void Area();
}

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

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

class Circle:Shape
{
public override 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