A class containing at least one pure virtual function — cannot be instantiated directly, only used as a base for derived classes.

class Shape           // abstract -- has a pure virtual function
{
public:
    virtual double area() = 0;
};

// Shape s;   // ERROR

Shape* s = new Circle(5);   // OK -- can still use it via a pointer to a CONCRETE derived class

An abstract class may still contain regular (non-pure) member functions with real implementations — it just needs at least one pure virtual function to qualify as abstract.

The defining rule and what it means practically

A class becomes abstract the moment it has even one pure virtual function — regardless of how many other fully-implemented methods it has.

class Shape
{
public:
    virtual double area() = 0;              // pure virtual -- makes Shape abstract
    void printInfo() { cout << "A shape\n"; }   // regular, fully implemented -- doesn't change the abstractness
};

// Shape s;             // ERROR -- abstract, cannot instantiate
Shape* s = new Circle(5);   // OK -- pointer to abstract class is fine, as long as Circle is concrete

Purpose: defining a contract, not an implementation

An abstract class exists to say "every shape MUST have an area, but I won't say how" — it defines what derived classes must provide, without dictating how. This is the core idea behind interface-style design in C++.

Abstract classes CAN have constructors

class Shape
{
protected:
    string color;
public:
    Shape(string c) : color(c) {}   // abstract classes CAN have constructors -- called by derived class constructors
    virtual double area() = 0;
};

class Circle : public Shape
{
    double radius;
public:
    Circle(string c, double r) : Shape(c), radius(r) {}   // must call Shape's constructor
    double area() override { return 3.1416 * radius * radius; }
};

A common misconception: "abstract means no constructor." False — the constructor still runs (to initialize shared state like color), it just can never be called to create a Shape object directly, only as part of constructing a derived object.

Important MCQs

  1. A class becomes abstract as soon as it has:
  2. Can an abstract class have a constructor?
  3. Can you create a pointer of an abstract class type pointing to a concrete derived object?

Self-Test Questions

  1. Can an abstract class have fully-implemented (non-pure) member functions? Give an example use case.
  2. Why can an abstract class still have a constructor if it can never be instantiated directly?
  3. What is the practical purpose of declaring a class abstract, rather than just leaving area() unimplemented with an empty body?