简体   繁体   中英

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?

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");
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM