Click here to Skip to main content
15,888,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can an abstract class implement an interface?


An abstract class can implement from an interface.
In this case, we must provide method body for all methods it implemented from the interface.


using System;
interface IBaseInterface
{
void Function1();
}

abstract class AbsClass : IBaseInterface
{
public void Function1()
{
Console.WriteLine("Function implemented from the IBaseInterface");
}
}

class DerivedClass : AbsClass
{
}
class MainClient
{
public static void Main()
{
MainClass mc = new MainClass();
mc.Function1();
}
}
}
}
Posted
Updated 8-Dec-09 20:09pm
v3

1 solution

I think the code you wrote is ok but if you want to force the developer to implement the interface in the DerivedClass then i think it's not gonna work
but if it's optional you can ovveride it in the DerivedClass

Another senario you can implement the interface and inherit the base class in the derived class and now you get the power of the 2 objects
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900