Anonymous

Can We Create Object Of Interface?

6

6 Answers

Anonymous Profile
Anonymous answered
Hello Friends,

Actually in c# we can Create object for an Interface.

Example:

Interface Myinterface
    {
  public void MyMethod();
    }

public class MyBaseClass : Myinterface
    {
  public virtual void MyMethod()
  {
  MessageBox.Show("MyBaseClass");
  }
    }

In Some other Class you can Create object for the Interface as follows,

MyBaseClass objMyBaseClass=new MyBaseClass();
Myinterface objMyinterface = (Myinterface)objMyBaseClass;
Rinav Gangar Profile
Rinav Gangar answered
Nope,

Interfaces is Incomplete. Creating Objects is not allowed, as you cannot create objects of incomplete Entities (classes)

it is the job of the Classes that implement the interface to make them concrete, or mark the class as abstract.

hope it helps

any further assistance, msg me

thanked the writer.
Anonymous
Anonymous commented
Yes its abosolutely correct. We can not create an instance for interface. Interface can be implemented into any sub-class and by using subclass object we can call the method in the interface.
Senthil Kumaran Gurusamy Profile

Hey Guys


I agree for the same but I am having doubt.


Connection is an interface, Which is used for database connection in java.


For this Connection interface we use to create an object to establish connection.


Could you please clarify my doubt.


Thanks in advance

Anonymous Profile
Anonymous answered
Yes we can create object for an interface, but the object has to reference subclass implementing the interface.
Anonymous Profile
Anonymous answered
My  question is can we create object for interface?
It is possible or not?
Pls reply immediately...

Answer Question

Anonymous