Lalit Raghav

Lalit Raghav

  • 687
  • 1.4k
  • 94.4k

Interface use

May 6 2015 2:28 AM
namespace InterFaceDemo
{

   //defining First interface

    interface ISum

    {

        void sum(int a, int b);

    }

 

//defining second interface which inherits first interface

    interface ISubtract:ISum

    {

        void sub(int a, int b);

    }

 

//defining class which inherits second interface

 

    class NewClass : ISubtract

    {

//implementing interface defined methods

        public void sum(int a, int b)

        {
Console.WriteLine((a+b).ToString());
        

        }

        public void sub(int a, int b)

        {

          Console.WriteLine((a-b).ToString());

        }

    }


    class Program
    {
        static void Main(string[] args)
        {
            //creating instance of class
            NewClass newclass = new NewClass();
            //calling sum() of ISum interface
            newclass.sum(4,5);
            //calling sub() of ISubtract interface
            newclass.sub(5,8);

        }
    }
}





here i want to know that we have use interface .But we can call add and subtract method with out use interface.then what is need of interface .






Answers (1)