Back to C++ Notes
Topic #94

C++ Inheritance


Inheritance

Inheritance allows one class to reuse attributes and methods from another class. It helps you write cleaner, more efficient code by avoiding duplication.

We group the "inheritance concept" into two categories:

  • derived class (child) - the class that inherits from another class
  • base class (parent) - the class being inherited from

To inherit from a class, use the : symbol.

In the example below, the Car class (child) inherits the attributes and methods from the Vehicle class (parent):

Example

// Base class
class Vehicle {
  public:

string brand = "Ford";
    void honk() {

cout << "Tuut, tuut! \n" ;
    }
};

// Derived
class
class Car: public Vehicle {
  public:

string model = "Mustang";
};

int main() {
  Car myCar;

myCar.honk();
  cout << myCar.brand + " " + myCar.model;

return 0;
}

Note: Why And When To Use "Inheritance"? - It is useful for code reusability: reuse attributes and methods of an existing class when you create a new class.

Want to go beyond the notes?

Join Coding Now Tech Institute's C++ course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

C++ Inheritance – FAQs

Quick answers about learning C++ Inheritance in C++.

This free note from Coding Now Tech Institute explains C++ Inheritance in C++ — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every C++ topic on Coding Now Tech Institute, including C++ Inheritance, is 100% free with no signup required.
With focused practice, most students grasp C++ Inheritance in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now