C++20 sections · 1024 units
Open in Course

Base Class and Derived Class

Parent and child relationship

The original class is called the base class or parent class. The new class that inherits from it is called the derived class or child class. A derived class extends or specializes the base class.

In C++, you declare inheritance with a colon: class Dog : public Animal { }; Here Animal is the base class and Dog is derived. The public keyword controls how inheritance affects member access.

A derived class object contains a complete base class sub-object inside it. When you create a Dog, memory is allocated for both Animal members and Dog-specific members together.