I have written the following code in C#.NET
public interface IWork
{
void func();
}
public abstract class WorkClass
{
public void func()
{
Console.WriteLine("Calling Abstract Class Function");
}
}
public class MyClass:WorkClass,IWork
{
}
On compiling, I didn't get any error. Compiler is not forcing me to implement the method "func();" in "MyClass", which has been derived from the interface "IWork".Latter, I can gracefully create a instance of the class "MyClass" and call the function "func()". Why the compiler is not forcing me to implement the "func()" method in the "MyClass"(which has been derived from "IWork" interface? Is it a flaw in C#?
MyClassinherits this functions from the abstract classWorkClass- therefore it is implemented.classor lose it in yourinterfaceand mark itabstractin your baseclass.IDogand with that I promise it will be able toPoo(). Whetherclass Dog:Animal,IAnimalimplements it or not is not an issue whenclass Animalimplements it. The promise is met.