By this time, if you have understood the importance between abstract class
and interface, I don't have to throw light on them.
But, thought to place some code, so that it would be meaningful for you
understand how each will behave and their respective advantages.
---------------------------------------------------------
public interface TopInterface
{
void DoSome();
}
public abstract class TopAbsClass
{
public TopAbsClass()
{
cs.WriteLine("From Private Constructor.."); // You have the
flexibility to embed your code here, which will execute every time the
inherited class initialized
}
public abstract void DoSomeWork();
}
public class FirstLevelInheritanceClass : TopAbsClass, TopInterface
{
public override void DoSomeWork() // this method is from Abstract
Class
{
Console.WriteLine("Printed from FirstLevelInheritanceClass -
DoSomeWork() Method is executed");
}
public void DoSome() // This method is from the interface
{
Console.WriteLine("Printed from FirstLevelInheritanceClass -
DoSome() Method is executed");
}
}
---------------------------------------------------------
It is recommended to use interfaces, only due to "no code but template".
Hope this helps you
"rhaazy" <rh****@gmail.comwrote in message
news:dd**********************************@l64g2000 hse.googlegroups.com...
Why would I ever use an interface when I could use an abstract class?
Assuming the only limitation is only having one base class, would this
change assuming you could implement multiple inheritance (and
guarantee not creating ambiguity issues)?
Please share your thoughts or explain something to me if I seem to be
confused.