Is it Possible Instantiate the Interface?

Posted by Satyadnet under C# on 4/24/2009 | Views : 12620 | Status : [Member] | Replies : 2
Hi everyone,
Please let me know : Is it Possible Instantiate the Interface?

Thanks.




Responses

Posted by: Vuyiswamb on: 4/27/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down

You Implement Interfaces. C# does not support multiple inheritance so we impement interfaces when we declare the class like this

// C#
public class BusinessAccountclass : IAccount, ICustomer, IPortfolio
{
// Code to implement class here.
}


IAccount and ICustomer are interfaces they are declared like this

// C#

public interface IAccount
{
void DeductFees(IFeeSchedule feeSchedule);
void PostInterest();
decimal Balance
{
get;
set;
}
}


Thank you for Posting at DotnetFunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Satyadnet, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rameshsree on: 4/28/2009 [Member] Starter

Up
0
Down
One can't instantiate an interface. One can get a reference to an interface.

Let's say Class A implements interface iA then we can't instantiate IA
like IA a = new IA() -- this gives compilation error.

but we can get the referance to interface as below

IA a = new A()



Satyadnet, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response