Here is the simple inheritance
public class BaseClass
{
public string Draw()
{
return "Draw from BaseClass";
}
}
public class ChildClass:BaseClass
{
public string Draw()
{
return "Draw from ChildClass";
}
}
static void Main(string[] args)
{
ChildClass c = new ChildClass();
console.writeline(c.Draw());
}
The above implementation will print
Draw from Childclass
Here is the usage with the override
public class BaseClass
{
public virtual string Draw()
{
return "Draw from BaseClass";
}
}
public class ChildClass:BaseClass
{
public override string Draw()
{
return "Draw from ChildClass";
}
}
static void Main(string[] args)
{
ChildClass c = new ChildClass();
console.writeline(c.Draw());
}
The above implementation will print
Draw from Childclass
So what is the difference between above 2 Inheritance Implementation.
In the second snippet Draw is declared to be virtual, this means that you can call the inherited method from a variable of type
BaseClass.Documentation
Funny thing.. the second link in the list above uses the same snippets as you’ve provided.