- If instance member declared as
virtual
in base class, then it will continue to remainvirtual
in derived classes until it will not be marked assealed
. - Avoid to using
new
keyword because it breaks polymorphism (see your example with Draw method - it should be marked as virtual).
Example of broken polymorphism:
public class Base
{
public void Method()
{
Console.WriteLine("Base.Method()");
}
}
public class Derived : Base
{
public new void Method()
{
Console.WriteLine("Derived.Method()");
}
}
Derived obj = new Derived();
obj.Method(); // Will output "Derived.Method()"
((Base)obj).Method() // Will output "Base.Method()"
It is not you usually expect when you works with class hierarchies. It should not make a difference whether you call Method() from base class or from derived one.