Sahil Sharma
Can we create instance of an interface? If yes, How?
By Sahil Sharma in .NET on Aug 30 2014
  • ragini varshney
    Nov, 2014 28

    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());

    • 2
  • Rakesh Kumar
    Sep, 2014 14

    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

    • 1
  • Durga Shankar
    Oct, 2018 10

    no

    • 0
  • Mukesh Kumar
    Sep, 2017 5

    No

    • 0
  • Suresh Mogudala
    Sep, 2014 12

    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();

    • 0
  • neeraj gupta
    Sep, 2014 6

    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 {}

    • 0
  • kavita singh
    Sep, 2014 4

    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();

    • 0
  • arvind
    Sep, 2014 3

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

    • 0
  • Sahil Sharma
    Sep, 2014 3

    @Himanshu Tomar: I have the same code but still confused about the implementation. See the link: http://www.c-sharpcorner.com/Forums/Thread/267281/

    • 0
  • Himanshu  Tomar
    Sep, 2014 3

    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(); }

    • 0
  • Jitendra Patel
    Sep, 2014 2

    Cannot create an instance of the abstract class or interface.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS