Thursday, February 5, 2026

abstract class

1. What is an Abstract Class?

An abstract class is a partially implemented class.
It can have both abstract methods (no body) and normal methods (with body).

2. Key rule

  • An abstract class cannot be instantiated

  • It must be inherited by another class

3. What can an abstract class contain?

  • Abstract methods

  • Non-abstract (normal) methods

  • Fields

  • Properties

  • Constructors

4. Syntax example (interview-friendly)

abstract class Employee
{
    public abstract void Work();

    public void Login()
    {
        // common code
    }
}

class Developer : Employee
{
    public override void Work()
    {
        // implementation
    }
}

5. Method implementation rule

  • Abstract methods must be overridden in the derived class

  • Normal methods are optional to override

6. Inheritance rule

  • Supports single inheritance only

  • Multiple inheritance is not allowed with classes

7. Abstract class vs Interface (short point)

  • Abstract class → Partial abstraction

  • Interface → Complete abstraction

8. Why do we use abstract classes?

  • To share common base functionality

  • To enforce base rules with flexibility

  • When some behavior is common and some is different

9. Important interview one-liner

An abstract class provides a base class with both implemented and unimplemented methods.