Yes, abstract methods are virtual by definition; they must be redefined in order to actually be overridden by subclasses:
When an instance method declaration includes an abstract modifier, this method is called an abstract method. Although an abstract method is also an implicit virtual method , it cannot have a virtual modifier.
Conversely, you cannot declare an abstract non-virtual method, because if you could, you would have a method that cannot be implemented and therefore can never be called, which makes it useless.
However, if you want the class to implement an abstract method, but not allow any of its subclasses to change its implementation, then where is sealed . Example:
abstract public class AbstractClass { abstract public void DoSomething(); } public class BaseClass : AbstractClass { public sealed override void DoSomething() { Console.WriteLine("Did something"); } }
Note that although the abstract method is (implicitly) virtual, the implementation in a particular base class is not virtual (due to the sealed ).
Boltclock
source share