---
title: "Inheritance in C++"  
description: "In this blog, I’m explaining about Inheritance in C++  Inheritance is the ability to create a class from another class, the “parent” class, extending"  
author: "priyanka kushwaha"  
published: 2015-02-05  
updated: 2015-02-05  
canonical: https://www.mindstick.com/blog/756/inheritance-in-c-plus-plus  
category: ".net"  
tags: ["c#", ".net", "oops", "inheritance"]  
reading_time: 2 minutes  

---

# Inheritance in C++

In this blog, I’m explaining about Inheritance in C++\

Inheritance is the ability to create a class from another class, the “parent” class, extending the [functionality](https://www.mindstick.com/blog/136/using-watermark-functionality-in-textbox-by-jquery) and state of the parent in the derived, or “child” class. It allows derived classes to overload methods from their parent class.

##### Types of inheritance in C++

1. Single Inheritance

2. [Multilevel Inheritance](https://www.mindstick.com/interview/23096/can-you-explain-me-multilevel-inheritance)

3. [Multiple Inheritance](https://www.mindstick.com/forum/159471/how-does-c-plus-plus-support-multiple-inheritance-and-what-are-potential-issues-associated-with-it)

4. Hierarchical Inheritance

5. Hybrid Inheritance (also known [as Virtual](https://www.mindstick.com/forum/212/can-be-declare-a-static-function-as-virtual) Inheritance)

##### Syntax :

Class DeriveName: Access Specifier BaseClass

\
1. In Single Inheritance [base class](https://www.mindstick.com/blog/116/base-class-initilization) functionality access in derive class.

2. In Multilevel Inheritance a [Derived class](https://answers.mindstick.com/qa/30686/what-is-a-base-class-and-derived-class) can also inherited by another class

3. Multiple Inheritance is that in which a class inherits the [features](https://www.mindstick.com/articles/12993/5-advanced-features-for-your-odoo-ecommerce-theme) from two Base Classes when a Derived Class takes features from two Base class

4. Hierarchical Inheritance in which a Base class is inherited by many [sub class](https://answers.mindstick.com/qa/92538/what-are-the-base-class-sub-class-and-superclass).

5. Hybrid Inheritance : This is a Mixture of two or More inheritance and in this Inheritance a Code may contains two or three types of inheritance in single code.

##### Example

```
// Inheritance.cpp : main project file. #include "stdafx.h"#include <iostream>using namespace System;using namespace std;  class  Rectangle{public:            double length,breadth;            void  get(double l,double b)            {                        length=l;                        breadth=b;            }            double   area()            {                        return(length*breadth);            }            Rectangle();            ~ Rectangle(); private: }; public class Cube:public Rectangle     //Single inheritance{public:Rectangle obj;public: double height;                        double  area()                        {double res;                                    res=obj.area();                                    return(res*height);                        }                        void get(double l,double b,double h)                        {                                    obj.length=l;                           obj.breadth=b;                                    height=h;                        }            Cube();            ~Cube(); private: };   Cube::Cube(){} Cube::~Cube(){}  Rectangle:: Rectangle(){}  Rectangle::~ Rectangle(){}int main(array<System::String ^> ^args){            Cube  Ref;            double result;            Ref.get(2,3,3);            result=Ref.area();            cout<<"Area of cube";            cout<<result;                        Console::ReadKey(0);    return 0;}
```

---

Original Source: https://www.mindstick.com/blog/756/inheritance-in-c-plus-plus

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
