Вот простое наследование
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());
}
Вышеприведенная реализация выведет Draw из Childclass
Вот использование с переопределением
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());
}
Вышеприведенная реализациянапечатает Draw из Childclass
Так в чем же разница между вышеупомянутыми 2 реализациями наследования.