Are abstract methods virtual?

Yes, abstract methods are virtual by definition; they must be overridable in order to actually be overridden by subclasses:

When an instance method declaration includes an abstract modifier, that method is said to be an abstract method. Although an abstract method is implicitly also a virtual method, it cannot have the modifier virtual.

Conversely you can't declare an abstract non-virtual method, because if you could, you would have a method that can't be implemented and thus can never be called, making it rather useless.

However, if you want to have a class implement an abstract method but not allow any of its subclasses to modify its implementation, that's where sealed comes in. An example:

abstract public class AbstractClass
{
    abstract public void DoSomething();
}

public class BaseClass : AbstractClass
{
    public sealed override void DoSomething()
    {
        Console.WriteLine("Did something");
    }
}

Notice that while the abstract method is (implicitly) virtual, the implementation in the concrete base class is non-virtual (because of the sealed keyword).


Yes, they are virtual. Otherwise you would have no way to write implementation for them.

Tags:

C#