Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 697
user490112 Avatar asked Dec 20 '22 19:12

user490112


1 Answers

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");
    }
}
like image 190
FishBasketGordo Avatar answered Feb 16 '23 00:02

FishBasketGordo