Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Aditi Msc   on Nov 14 In Java Category.

  
Question Answered By: Sherri Parker   on Nov 14

is there any way that an interface  can instantiate? how?
if it can be done...then what property  that object  would hold?

There is no way the you can instantiate an interface or an abstract class.
You can only instantiate the class implementing the interface or a class
that extends abstract class.

say you have an interface "InterfaceOne" as follows

public interface InterfaceOne
{

public void methodOne();

}


then you have to write a class as follows

public class InterfaceOneImpl implements InterfaceOne
{
public void methodOne()
{
// logic goes here
}
}

Then you can have a statement


InterfaceOne intf=new InterfaceOneImpl();
intf.methodOne();

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on instance of an interface Or get search suggestion and latest updates.


Tagged: