Interviews11 answers
Can we create instance of an interface? If yes, How?
11 Answers
no
Durga ShankarPosted Oct 9, 2018, 9:27 PM EDT
No
Mukesh KumarPosted Sep 5, 2017, 12:01 AM EDT
Yes , we create of instance of Interface.
Interface L1
{
void Add();
}
class ABC:L1
{
void Add()
{
Console.writeline("H r u");
}
}
L1 obj=new ABC();
Console.writeline(obj.Add());
ragini varshneyPosted Nov 28, 2014, 7:55 AM EST
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
Rakesh KumarPosted Sep 14, 2014, 12:37 AM EDT
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();
Suresh MogudalaPosted Sep 11, 2014, 9:44 PM EDT
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
{
}
neeraj guptaPosted Sep 5, 2014, 9:30 PM EDT
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();
kavita singhPosted Sep 4, 2014, 4:43 AM EDT
@Himanshu Tomar: I have the same code but still confused about the implementation. See the link: http://www.c-sharpcorner.com/Forums/Thread/267281/
Sahil SharmaPosted Sep 3, 2014, 4:53 AM EDT
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();
}
Himanshu TomarPosted Sep 3, 2014, 3:59 AM EDT
Cannot create an instance of the abstract class or interface.
Jitendra PatelPosted Sep 2, 2014, 2:19 AM EDT



