It allows us to create a new class (derived class) from an existing class (base class) . The derived class inherits the features from the base class and can have additional features of its own. For example, class Animal { // eat() function // sleep() function }; class Dog : public Animal { // bark() function };
What is inheritance in C++ give an example?
It allows us to create a new class (derived class) from an existing class (base class) . The derived class inherits the features from the base class and can have additional features of its own. For example, class Animal { // eat() function // sleep() function }; class Dog : public Animal { // bark() function };