Junior — Middle
Explain what is meant by an abstract method in object-oriented programming
sobes.tech AI
Answer from AI
An abstract method in object-oriented programming is a method declared in an abstract class or interface but without an implementation. It serves as a template that must be implemented by all subclasses of that class.
In C#, an abstract method is declared with the abstract keyword and does not contain a body:
abstract class Animal
{
public abstract void MakeSound();
}
class Dog : Animal
{
public override void MakeSound()
{
Console.WriteLine("Woof");
}
}
Thus, an abstract method sets a mandatory contract for subclasses, ensuring polymorphism and enabling the creation of flexible architectures.