user490112
user490112

Reputation: 85

Can abstract class be override in derived class without implementing in base class

I have an abstract class A with one abstract method.

This class is inherited by another class, B, that should not implement the abstract method.

Now another class, C, needs to inherit from class B and implement the method defined in class A.

How can I do this?

Upvotes: 4

Views: 1522

Answers (1)

FishBasketGordo
FishBasketGordo

Reputation: 23142

You would need to mark class B as an abstract class as well if it's not going to implement all of the abstract members of its base class. Then, just override as normal in class C.

Example:

public abstract class A
{
    public abstract void DoStuff();
}

public abstract class B : A
{
    // Empty
}

public class C : B
{
    public override void DoStuff()
    {
        Console.WriteLine("hi");
    }
}

Upvotes: 11

Related Questions