Friday, 1 September 2017

C# program to implement the use of implement Interface

C# program example to use of implement Interface in C# program

Program

using System;
interface area
    {
        double calc(double x);
    }
     class B : area
    {
        public double calc(double x)
        {
            return x * x;
        }
     }
     class C : B
    {
        public double calc(double x)
        {
            return Math.PI * x * x;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            C c = new C();
             double d= c.calc(5.5);
             Console.WriteLine("Area 1: {0}", d);

            area a;
            B b = new B();
             a = b as area;
             double r = a.calc(6.5);
             Console.WriteLine("Area 2: {0}", r);
            
        }

     } 

Output


0 comments:

Post a Comment