We can't create instance of interface which holds reference of it's own type.
interface IExample
{
void abc();
}
IExample obj=new IExample();// Not Possible
But Interface object can hold reference of its derived class.
public class Example:IExample
{
public void abc()
{
some code;
}
}
IExample obj=new Example();// Possible and correct
You can't Create Instance of Interface,But you can create reference to the Interface by using Child class reference object
like
ParentInterface objParent=new ChildClassName();
objParent.ParentInterfaceMethodshere();
interface can not be instantiated,but instance of interface can also be created provided the body is added to the interface at the time of instantiation which normally class provides;
interface iabc
{
}
Interface can not be directly instantiated. We can create an instance of a class that implements the interface, then assign that instance to a variable of the interface type.
IControl c= new DemoClass();
public interface Interface1
{
void ImplementLogic();
}
public class Class1: Interface1
{
public void ImplementLogic()
{
// Implement your logic
}
}
public class Class2
{
// Creating Instance of Interface
Interface1 iterfaceObject = new Class1();
}