10
Reply

Can we create instance of an interface? If yes, How?

Sahil Sharma

Sahil Sharma

Aug 30, 2014
7k
1

    No

    Mukesh Kumar
    September 05, 2017
    0

    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 varshney
    November 28, 2014
    0

    We can't create instance of interface which holds reference of it's own type. interface IExample {void abc(); } IExample obj=new IExample();// Not PossibleBut 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 Kumar
    September 14, 2014
    0

    You can't Create Instance of Interface,But you can create reference to the Interface by using Child class reference objectlike ParentInterface objParent=new ChildClassName(); objParent.ParentInterfaceMethodshere();

    Suresh Mogudala
    September 12, 2014
    0

    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 gupta
    September 06, 2014
    0

    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 singh
    September 04, 2014
    0

    Interface1 iterfaceObject = new Class1(); //can do this

    arvind
    September 03, 2014
    0

    @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 Sharma
    September 03, 2014
    0

    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 Tomar
    September 03, 2014
    0

    Cannot create an instance of the abstract class or interface.

    Jitendra Patel
    September 02, 2014
    0