🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
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 CodingNow 2.0'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 CodingNow 2.0 explains C++ Inheritance in C++ — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every C++ topic on CodingNow 2.0, 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 CodingNow 2.0'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 CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now