Interfaces in C#

Interfaces in C#
Interface is a set of abstract methods, that must be implemented by the child classes.

interface IName
{
    DataType MethodName(param1, …);
}
 
Child Class of Interface
class ChildClassName : IName
{
    public DataType MethodName(param1, …)
    {
    }
}
 
1. The child class that implements the interface, MUST implement ALL METHODS of the interface.
2. Interface methods are by default “public” and “abstract”.
3. The child class must implement all interface methods, with same signature.
4. You can’t create object for interface.
5. You can create reference variable for the interface.
6. The reference variable of interface type can only store the address of objects of any one of the corresponding child classes.
7. You can implement multiple interfaces in the same child class [Multiple Inheritance].

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply