March 15, 2007
Class provides a definition to override the interface’s abstract definitions. This is one of the ways interface is defined.
But in the following example the program Employee class doesn’t provide a definition to override the interface’s abstract definitions. The situation is same in the Animal abstract class as well. That means there is no keyword “override” when defining Work() method within the Employee class and within the Animal abstract class. Anybody explain please.
using
public
{
string Work();
}
class
private string name;
public Employee(string name)
this.name = name;
public string GetName()
return name;
public string Work()
return "I do my job";
abstract
protected string name;
public Animal(string name)
public abstract string Work();
public Dog(string name): base(name)
public override string Work()
return "I watch the house";
public Cat(string name) : base(name)
return "I catch mice";
public static void Main()
Employee bob = new Employee("Bob");
Dog spot = new Dog("Spot");
Cat puff = new Cat("Puff");
Console.WriteLine("{0} says {1}", bob.GetName(), bob.Work());
Console.WriteLine("{0} says {1}", spot.GetName(), spot.Work());
Console.WriteLine("{0} says {1}", puff.GetName(), puff.Work());
/*
Output:Bob says I do my job
Spot says I watch the house
Puff says I catch mice
*/