How to Create a Derived Class from a Base Class in C++? Last Updated : 18 Mar, 2024 Comments Improve Suggest changes Like Article Like Report In C++, one of the fundamental concepts of Object Oriented Programming (OOPS) is inheritance, allowing users to create new classes based on existing classes. The class that inherits another class is called derived class and the class that is inherited is called base class. In this article, we will learn how to create a derived class from a base class in C++. Create a Derived Class in C++We can use the concept of inheritance in C++ which is a process in which one object acquires all the properties and behaviors of its parent object automatically. Using this, we can create a new class from an existing class where the existing class is the base class (or parent class), and the new class is the derived class (or child class). Syntax to Inherit a Classclass BaseClass_Name{ //body of class};class DerivedClass_Name : access-specifier Baseclass_Name{ //body of class};Here, the access specifier assigns accessibility of the base class members in the derived class. For example, if the access specifier is private, then all the members of the base class will be private in the derived class. C++ Program to Create a Derived Class from a Base ClassThe following program illustrates how we can create a derived class from a base class in C++. C++ // C++ Program to illustrate how to create a derived class // from a base class #include <iostream> using namespace std; // Base class class Base { public: // Base class method void basePrint() { cout << "Method of Base class called" << endl; } }; // Creating a derived class from base class class Derived : public Base { public: // Derived class method void derivedPrint() { cout << "Method of Derived class called" << endl; } }; int main() { // creating an object of derived class Derived obj2; // calling function of base class using an object of // derived class obj2.basePrint(); // calling function of derived class obj2.derivedPrint(); return 0; } OutputMethod of Base class called Method of Derived class calledTime Complexity: O(1)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article How to Create a Derived Class from a Base Class in C++? G gaurav472 Follow Improve Article Tags : C++ Programs C++ cpp-class cpp-inheritance C++-Class and Object C++-Inheritance CPP Examples +3 More Practice Tags : CPP Similar Reads How to Override a Base Class Method in a Derived Class in C++? Function overriding is a concept in object-oriented programming languages, in which a function/method of a parent class is redefined in its child class to change its behavior for the objects of the child class. In this article, we are going to learn how to override a base class function in a derived 2 min read How to Call a Virtual Function From a Derived Class in C++? In C++, virtual functions play an important role because they allow the users to perform run-time polymorphism. While dealing with inheritance and virtual functions, it is very crucial to understand how to call a virtual function from a derived class. In this article, we will learn how to call a vir 2 min read How to Declare a Copy Constructor in a Derived Class? In C++, a copy constructor is a constructor that initializes an object as a copy of an existing object of the same class. In this article, we will learn how to declare a copy constructor in a derived class. Declaring a Copy Constructor in a Derived ClassWe can declare a copy constructor in a derived 3 min read Base Class Pointer Pointing to Derived Class Object in C++ Prerequisite: Pointers in C++ A pointer is a data type that stores the address of other data types. Pointers can be used for base objects as well as objects of derived classes. A pointer to the object of the derived class and a pointer to the object of the base class are type-compatible (may be used 3 min read How to Create a Class with Constructors and Destructors in C++? In C++, a class is a user-defined data type encapsulating data members and member functions. The constructors and destructors are special member functions of a class used for initializing objects and cleaning up resources respectively. In this article, we will discuss how to create a class with cons 2 min read Like