Monday, 5 November 2012

Program for multiple implimentation of an interface


using System;
interface Area
{
 double Compute(double x);
}
class Square : Area
{
 public double Compute(double x){ return x*x; }
}
class Circle : Area
{
 public double Compute(double x){ return Math.PI*x*x; }
}
class InterfaceTest
{
 static void Main()
 {
  Square sqr=new Square();
  Circle cir=new Circle();
  Area area;
  area= sqr as Area;
  Console.WriteLine("Area of square(10.0 cm) = "+area.Compute(10.0));
  area= cir as Area;
  Console.WriteLine("Area of circle(10.0 cm) = "+area.Compute(10.0));
  Console.ReadKey();
 }
}

Output:-

No comments:

Post a Comment