Sobes.tech
Junior — Middle

Is it possible to implement an inheritance chain using only abstract classes?

sobes.tech AI

Answer from AI

Yes, in C# it is possible to implement an inheritance chain using only abstract classes. An abstract class can inherit from another abstract class, thus creating a chain.

For example:

public abstract class Animal {
    public abstract void MakeSound();
}

public abstract class Mammal : Animal {
    public abstract void Walk();
}

public class Dog : Mammal {
    public override void MakeSound() {
        Console.WriteLine("Bark");
    }

    public override void Walk() {
        Console.WriteLine("Dog is walking");
    }
}

Here, Mammal inherits from Animal, both are abstract, and Dog implements the concrete methods. Thus, an inheritance chain of abstract classes is quite possible.

Is it possible to implement an inheritance chain… - sobes.tech