You are on page 1of 3

using

using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace AbstractDemo
{
class Program
{
static void Main(string[] args)
{
AreaFinder finder = new AreaFinder();
Circle c1=new Circle("2D",10.5);
Circle c2=new Circle("2D",1.2);
Rectangle r= new Rectangle("2D",10,10);
finder.DisplayArea(c1);
finder.DisplayArea(c2);
finder.DisplayArea(r);
}
}
}

################################################################################
##################################

using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace AbstractDemo
{
abstract class Shape
{
string dimension;
public Shape(string _dimension)
{
dimension = _dimension;
}
public string GetDimension()
{
return dimension;
}
public abstract double Area();
}
}

################################################################################
##################################

using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace AbstractDemo
{
class Circle:Shape
{
double radius;
public Circle(string dim,double _radius)
: base(dim)
{
radius = _radius;
}
public override double Area()
{
Console.WriteLine(GetDimension());
return 3.1416 * radius * radius;
}
}
}

################################################################################
###################################

using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace AbstractDemo
{
class Rectangle:Shape
{
double length;
double breadth;
public Rectangle(string dim, double _length, double _breadth)
: base(dim)
{
length = _length;
breadth = _breadth;

}
public override double Area()
{
return length * breadth;
}
}
}

################################################################################
##################################

using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace AbstractDemo
{
class AreaFinder
{
public void DisplayArea(Shape s)/* It is possible to create a reference
of abstract base class.
We aren't creating any object of abst
ract base class,So this is allowed*/
{
Console.WriteLine("Area is :" + s.Area());
}
}
}

You might also like