An interfacelooks like a class, but has no implementation. The only thing it contains isdefinitions of events, indexers, methods and/or properties.The reason interfaces onlyprovide definitions is because they are inherited by classes and structs,which must provide an implementation for each interface member defined.

Example
//defining first interface
    interface Ifirst
    {
        voidsum(int a, intb);
    }
 
//definingsecond interface which inherits first interface
    interface Isecond:Ifirst
    {
        voidsub(int a, intb);
    }
 
//definingclass which inherits second interface
 
    class newClass : Isecond
    {
//implementinginterface defined methods
        public void sum(int a, int b)
        {
            MessageBox.Show("Sum is: " + (a + b).ToString());
        }
        public void sub(int a, int b)
        {
            MessageBox.Show("Difference is: " + (a - b).ToString());
        }
    }

Leave Comment