Interfaces:-
In layman’s terms we can say that interface is a pure abstract class with all methods abstract and no data members.
Interview definition:-
Interface is a contract between two parties. The contract is that all the parties implementing interfaces must implement all the methods declared in interfaces.
Abstract class V/s Interfaces:-
1.) Abstract class can contain data members. Interfaces can’t.
2.) Abstract class can contain non abstract methods too. Interfaces can’t.
3.) Default access specifier is abstract class is private but we can have other access specifiers also. Interfaces methods are by default public; you can’t apply any access specifier; not even public.
4.) In interfaces members are by default abstract you can’t even specify abstract keyword.
5.) Abstract class can implement interfaces. Interfaces can’t inherit classes but can implement other interfaces also.
6.) You can inherit from a single base class but you can implement multiple interfaces.
7.) Abstract classes are created using abstract keyword. Interfaces are created using interface keyword.
Here is an example of interface:-
public interface myinterfacse
{
void foo();
}
public interface myinterfacse1 : myinterfacse
{
void foo2();
}