{"id":4841,"date":"2019-03-15T22:28:58","date_gmt":"2019-03-15T16:58:58","guid":{"rendered":"https:\/\/www.csestack.org\/?p=4841"},"modified":"2024-02-11T12:13:44","modified_gmt":"2024-02-11T06:43:44","slug":"types-inheritance-cpp-program","status":"publish","type":"post","link":"https:\/\/www.csestack.org\/types-inheritance-cpp-program\/","title":{"rendered":"5 Types of Inheritance in C++ | Detail Explained with Program"},"content":{"rendered":"\n<h3 class=\"wp-block-heading has-text-align-center\" id=\"definition\">What is Inheritance in C++?<\/h3>\n\n\n\n<p>It is the technique of deriving a new class from the class which already exists.<\/p>\n\n\n\n<p>The new class is called the derived class and the old class is called the base class.<\/p>\n\n\n\n<p>You will understand more practically while going through this tutorial.<\/p>\n\n\n\n<p><strong>Advantages of Inheritance<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It is one of the prominent features offered by <a href=\"https:\/\/www.csestack.org\/object-oriented-programming-concepts\/\">object-oriented programming<\/a> which increases the reusability of the code.<\/li>\n\n\n\n<li>Reusing existing member functions reduces the lines of code.<\/li>\n<\/ul>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class Derived : access_modifier Base\n{\n&nbsp;&nbsp;Body of class Derived;\n}<\/pre>\n\n\n\n<p>The colon (:) indicates that the class Derived is derived from the class Base.<\/p>\n\n\n\n<p>The access modifier is either public or private.<\/p>\n\n\n\n<p>When it is public then the public and protected data members of Base become public members of Derived.<\/p>\n\n\n\n<p>When the access modifier is private, then the public and protected data members of Base become private members of Derived.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-align-center\" id=\"different-types\">Different Types of Inheritance in C++<\/h3>\n\n\n\n<p>On broadly classifying, there are 5 major types of inheritance.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"Single\">1. Single Inheritance<\/h4>\n\n\n\n<p>In this, only one class is derived from one base class.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"292\" height=\"122\" src=\"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Single-Inheritance.png\" alt=\"Single Inheritance\" class=\"wp-image-4851\"\/><\/figure><\/div>\n\n\n<p><strong>C++ Program for Single Inheritance:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;iostream&gt;\nusing namespace std;\n\nclass A\n{\n public:\n   int a,b;\n   void getdata()\n   {\n     cout&lt;&lt;&quot;Enter two numbers: &quot;&lt;&lt;endl;\n     cin&gt;&gt;a&gt;&gt;b;\n   }\n};\n\nclass B:public A\n{\n  int c;\n  public:\n   void showdata()\n   {\n     c=a*b;\n     cout&lt;&lt;&quot;The entered numbers are: &quot;&lt;&lt;a&lt;&lt;&quot; and &quot;&lt;&lt;b&lt;&lt;endl;\n     cout&lt;&lt;&quot;The product is: &quot;&lt;&lt;c&lt;&lt;endl;\n   }\n};\n\nint main()\n{\n B obj;\n obj.getdata();\n obj.showdata();\nreturn 0;\n}<\/pre><\/div>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Enter two numbers: 22 20\nThe entered number are&nbsp;20 and 22.\nThe product is 440<\/pre>\n\n\n\n<p>Here,<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Class B is inhering class A to access the function getdata().<\/li>\n\n\n\n<li>Object <code>obj<\/code> is the object of class B and it is calling inherited function <code>getdata()<\/code> of class A.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"multilevel\">2. Multilevel Inheritance<\/h4>\n\n\n\n<p>It is an extended version of single inheritance, where other classes are further derived from the derived class.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" width=\"451\" height=\"125\" src=\"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Multilevel-Inheritance.png\" alt=\"Multilevel Inheritance\" class=\"wp-image-4852\" srcset=\"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Multilevel-Inheritance.png 451w, https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Multilevel-Inheritance-300x83.png 300w\" sizes=\"(max-width: 451px) 100vw, 451px\" \/><\/figure><\/div>\n\n\n<p><strong>C++ Program for Multilevel Inheritance:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;iostream&gt;\nusing namespace std;\n\nclass A\n{\n  public:\n    int a,b;\n    void getdata()\n   {\n     cout&lt;&lt;&quot;Enter two numbers: &quot;&lt;&lt;endl;\n     cin&gt;&gt;a&gt;&gt;b;\n   }\n};\n\nclass B:public A\n{\n  public:\n    int c;\n    void avgdata()\n    {\n      c=(a*b)\/2;\n    }\n};\n\nclass C:public B\n{\n  public:\n    void showdata()\n    {\n      cout&lt;&lt;&quot;The entered numbers are &quot;&lt;&lt;a&lt;&lt;&quot; and &quot;&lt;&lt;b&lt;&lt;endl;\n      cout&lt;&lt;&quot;Their average is  &quot;&lt;&lt;c&lt;&lt;endl;\n    }\n};\n\nint main()\n{\n  C obj;\n  obj.getdata();\n  obj.avgdata();\n  obj.showdata();\n  return 0;\n}<\/pre><\/div>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Enter two numbers: 12 24\nThe entered numbers are 12 and 24\nTheir average is 18.<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"multiple\">3. Multiple Inheritance<\/h4>\n\n\n\n<p>In this, a derived class is invoked from more than one base class.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"339\" height=\"194\" src=\"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Multiple-Inheritance.png\" alt=\"Multiple Inheritance\" class=\"wp-image-4853\" srcset=\"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Multiple-Inheritance.png 339w, https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Multiple-Inheritance-300x172.png 300w\" sizes=\"(max-width: 339px) 100vw, 339px\" \/><\/figure><\/div>\n\n\n<p><strong>C++ Program for Multiple Inheritance:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;iostream&gt;\nusing namespace std;\n\nclass A\n{\n  public:\n    int i;\n    void geti()\n    {\n      cout&lt;&lt;&quot;Enter the number: &quot;&lt;&lt;endl;\n      cin&gt;&gt;i;\n    }\n};\n \nclass B\n{\n  public:\n    int j;\n    void evaluate()\n    {\n      if(j%2==0)\n      {\n        cout&lt;&lt;&quot;Entered number is even.&quot;&lt;&lt;endl;\n      }\n      else\n      {\n        cout&lt;&lt;&quot;Entered number is odd.&quot;&lt;&lt;endl;\n      }\n    }\n};\n \nclass C : public A, public B\n{\n  public:\n  void display()\n  {\n    cout&lt;&lt;&quot;Multiple inheritance successfully executed.&quot;&lt;&lt;endl;\n  }\n};\n \nint main()\n{\n  C obj;\n  obj.geti();\n  obj. j=obj.i;\n  obj.evaluate();\n  obj.display();\n  return 0;\n}<\/pre><\/div>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Enter the number: 76\nEntered number is even.\nMultiple inheritance successfully executed.<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"hierarchical\">4. Hierarchical Inheritance<\/h4>\n\n\n\n<p>In this, more than one derived classes are derived from one base class.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"314\" height=\"186\" src=\"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Hierarchical-Inheritance.png\" alt=\"Hierarchical Inheritance\" class=\"wp-image-4854\" srcset=\"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Hierarchical-Inheritance.png 314w, https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Hierarchical-Inheritance-300x178.png 300w\" sizes=\"(max-width: 314px) 100vw, 314px\" \/><\/figure><\/div>\n\n\n<p><strong>C++ Program for Hierarchical Inheritance:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;iostream&gt;\nusing namespace std;\n\nclass A\n{\n  public :\n    int a,b;\n    void getdata()\n    {\n      cout&lt;&lt;&quot;Enter the two operands: &quot;&lt;&lt;endl;\n      cin&gt;&gt;a&gt;&gt;b;\n    }\n};\n \nclass B : public A\n{\n  public:\n    int x,y;\n    void campare()\n    {\n      if(x&gt;y)\n      {\n        cout&lt;&lt;&quot;First operand is greater than the second one.&quot;&lt;&lt;endl;\n      }\n     else\n     {\n      cout&lt;&lt;&quot;Second operand is greater than the first one.&quot;&lt;&lt;endl;\n     }\n  }\n};\n \nclass C : public A\n{\n  public:\n    int p,q;\n    void calculate()\n    {\n      if(p%q==0)\n      {\n        cout&lt;&lt;&quot;First operand is divisible by the second one.&quot;&lt;&lt;endl;\n      }\n      else\n      {\n        cout&lt;&lt;&quot;First operand is not divisible by the second one.&quot;&lt;&lt;endl;\n      }\n    }\n};\n \nint main()\n{\n  B obj_1;\n  obj_1.getdata();\n  obj_1.a= obj_1.x;\n  obj_1.b= obj_1.y;\n  obj_1.campare();\n \n  C obj_2;\n  obj_2.getdata();\n  obj_2.a= obj_2.p;\n  obj_2.b= obj_2.q;\n  obj_2.calculate();\n  return 0;\n}<\/pre><\/div>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Enter the two operands: 23 31\nSecond operand is greater than the first one.\nEnter the two operands: 42 21\nFirst operand is divisible by the second one.<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"hybrid\">5. Hybrid Inheritance<\/h4>\n\n\n\n<p>When a combination of the above-mentioned types is used then it is called hybrid inheritance.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"330\" height=\"268\" src=\"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Hybrid-Inheritance.png\" alt=\"Hybrid Inheritance\" class=\"wp-image-4855\" srcset=\"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Hybrid-Inheritance.png 330w, https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Hybrid-Inheritance-300x244.png 300w\" sizes=\"(max-width: 330px) 100vw, 330px\" \/><\/figure><\/div>\n\n\n<p>As seen in the diagram above,<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Class B and class C are inherited from class A.<\/li>\n\n\n\n<li>Class D is inherited from two class B and class C.<\/li>\n<\/ul>\n\n\n\n<p>Indirectly class D is inherited from class A, twice, through class B and class C.<\/p>\n\n\n\n<p>Hence, class D will have two sets of copies of data members of class A. One through class B and the other through class C.<\/p>\n\n\n\n<p>This creates programming ambiguity and should be avoided. For this, you need to declare a base class as a virtual base class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-align-center\"><strong>What is the virtual base class?<\/strong><\/h3>\n\n\n\n<p>It can be avoided by making a common base class (ancestor class) as a &#8216;virtual base class&#8217; while declaring the direct or intermediate base classes.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class A\n{\n  Body of class A\n};\nclass B : virtual public A\n{\n  Body of class B\n};\n\nclass C : virtual public A\n{\n  Body of class C\n};\nclass D : public B, public C\n{\n  Body of class C\n};<\/pre>\n\n\n\n<p>When a class is made a virtual base class then special care is taken by C++ to make sure that only one copy of that class is inherited regardless of how many inheritance paths exist between the virtual base class and the derived class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"conclusion\">Conclusion:<\/h3>\n\n\n\n<p>Inheritance is one of the\u00a0very important concepts in C++ object-oriented programming. You will find many use-case scenarios of inheritance while working on your real project.<\/p>\n\n\n\n<p>Many get&nbsp;confused over multiple and multilevel inheritances. Hope after going through this tutorial you have cleared all your doubts.<\/p>\n\n\n\n<p>This is all about different types of inheritance in C++. If you have any further questions, please write in the comment section below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What are the different types of inheritance in c++? Difference between Multilevel vs multiple inheritances explained with the program.<\/p>\n","protected":false},"author":37,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,7],"tags":[297],"class_list":["post-4841","post","type-post","status-publish","format-standard","hentry","category-c-cpp","category-code","tag-cpp-oops"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>5 Types of Inheritance in C++ | Detail Explained with Program<\/title>\n<meta name=\"description\" content=\"What are the different types of inheritance in c++? Difference between Multilevel vs multiple inheritances explained with the program.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.csestack.org\/types-inheritance-cpp-program\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"5 Types of Inheritance in C++ | Detail Explained with Program\" \/>\n<meta property=\"og:description\" content=\"What are the different types of inheritance in c++? Difference between Multilevel vs multiple inheritances explained with the program.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.csestack.org\/types-inheritance-cpp-program\/\" \/>\n<meta property=\"og:site_name\" content=\"CSEstack\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/aniruddha.ca\" \/>\n<meta property=\"article:published_time\" content=\"2019-03-15T16:58:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-11T06:43:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Single-Inheritance.png\" \/>\n<meta name=\"author\" content=\"Tarshal Nimawat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@CSEStack\" \/>\n<meta name=\"twitter:site\" content=\"@ani_chaudhari\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tarshal Nimawat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.csestack.org\\\/types-inheritance-cpp-program\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/types-inheritance-cpp-program\\\/\"},\"author\":{\"name\":\"Tarshal Nimawat\",\"@id\":\"https:\\\/\\\/www.csestack.org\\\/#\\\/schema\\\/person\\\/d2a8982dffb39288166553349413d218\"},\"headline\":\"5 Types of Inheritance in C++ | Detail Explained with Program\",\"datePublished\":\"2019-03-15T16:58:58+00:00\",\"dateModified\":\"2024-02-11T06:43:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/types-inheritance-cpp-program\\\/\"},\"wordCount\":529,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/#\\\/schema\\\/person\\\/634ef1a9c4f38b0d340c6d45fa771218\"},\"image\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/types-inheritance-cpp-program\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.csestack.org\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/Single-Inheritance.png\",\"keywords\":[\"cpp oops\"],\"articleSection\":[\"C \\\/ C++\",\"Code\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.csestack.org\\\/types-inheritance-cpp-program\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.csestack.org\\\/types-inheritance-cpp-program\\\/\",\"url\":\"https:\\\/\\\/www.csestack.org\\\/types-inheritance-cpp-program\\\/\",\"name\":\"5 Types of Inheritance in C++ | Detail Explained with Program\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/types-inheritance-cpp-program\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/types-inheritance-cpp-program\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.csestack.org\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/Single-Inheritance.png\",\"datePublished\":\"2019-03-15T16:58:58+00:00\",\"dateModified\":\"2024-02-11T06:43:44+00:00\",\"description\":\"What are the different types of inheritance in c++? Difference between Multilevel vs multiple inheritances explained with the program.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/types-inheritance-cpp-program\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.csestack.org\\\/types-inheritance-cpp-program\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.csestack.org\\\/types-inheritance-cpp-program\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.csestack.org\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/Single-Inheritance.png\",\"contentUrl\":\"https:\\\/\\\/www.csestack.org\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/Single-Inheritance.png\",\"width\":292,\"height\":122,\"caption\":\"Single Inheritance\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.csestack.org\\\/types-inheritance-cpp-program\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.csestack.org\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"5 Types of Inheritance in C++ | Detail Explained with Program\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.csestack.org\\\/#website\",\"url\":\"https:\\\/\\\/www.csestack.org\\\/\",\"name\":\"CSEstack\",\"description\":\"Computer Science &amp; Programming Portal\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/#\\\/schema\\\/person\\\/634ef1a9c4f38b0d340c6d45fa771218\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.csestack.org\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.csestack.org\\\/#\\\/schema\\\/person\\\/634ef1a9c4f38b0d340c6d45fa771218\",\"name\":\"Aniruddha Chaudhari\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.csestack.org\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/Aniruddha-Chaudhari.jpg\",\"url\":\"https:\\\/\\\/www.csestack.org\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/Aniruddha-Chaudhari.jpg\",\"contentUrl\":\"https:\\\/\\\/www.csestack.org\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/Aniruddha-Chaudhari.jpg\",\"width\":634,\"height\":634,\"caption\":\"Aniruddha Chaudhari\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/Aniruddha-Chaudhari.jpg\"},\"description\":\"I am a Python enthusiast who loves Linux and Vim. I hold a Master of Computer Science degree from NIT Trichy and have 10 years of experience in the IT industry, focusing on the Software Development Lifecycle from Requirements Gathering, Design, Development to Deployment. I have worked at IBM, Ericsson, and NetApp, and I share my knowledge on CSEstack.org.\",\"sameAs\":[\"https:\\\/\\\/www.csestack.org\",\"https:\\\/\\\/www.facebook.com\\\/aniruddha.ca\",\"pythonwithani\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/aniruddha28\\\/\",\"https:\\\/\\\/x.com\\\/ani_chaudhari\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCw0a__B0eJsvCujkSIfLTAA\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.csestack.org\\\/#\\\/schema\\\/person\\\/d2a8982dffb39288166553349413d218\",\"name\":\"Tarshal Nimawat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6eab25d09918d2b55eb550432565aa0f07fab001482abd0d2bf5eb03832e991c?s=96&d=monsterid&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6eab25d09918d2b55eb550432565aa0f07fab001482abd0d2bf5eb03832e991c?s=96&d=monsterid&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6eab25d09918d2b55eb550432565aa0f07fab001482abd0d2bf5eb03832e991c?s=96&d=monsterid&r=g\",\"caption\":\"Tarshal Nimawat\"},\"description\":\"Tarshal is a tech-head CS undergrad, who is always on the lookout for the sharpest cutting edge techs in the business, be it Blockchain, hashgraphs or AI\\\/ML. With a knack for business development, negotiation and tech, she is often found educating those around her.\",\"url\":\"https:\\\/\\\/www.csestack.org\\\/author\\\/tarshal\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"5 Types of Inheritance in C++ | Detail Explained with Program","description":"What are the different types of inheritance in c++? Difference between Multilevel vs multiple inheritances explained with the program.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.csestack.org\/types-inheritance-cpp-program\/","og_locale":"en_US","og_type":"article","og_title":"5 Types of Inheritance in C++ | Detail Explained with Program","og_description":"What are the different types of inheritance in c++? Difference between Multilevel vs multiple inheritances explained with the program.","og_url":"https:\/\/www.csestack.org\/types-inheritance-cpp-program\/","og_site_name":"CSEstack","article_publisher":"https:\/\/www.facebook.com\/aniruddha.ca","article_published_time":"2019-03-15T16:58:58+00:00","article_modified_time":"2024-02-11T06:43:44+00:00","og_image":[{"url":"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Single-Inheritance.png","type":"","width":"","height":""}],"author":"Tarshal Nimawat","twitter_card":"summary_large_image","twitter_creator":"@CSEStack","twitter_site":"@ani_chaudhari","twitter_misc":{"Written by":"Tarshal Nimawat","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.csestack.org\/types-inheritance-cpp-program\/#article","isPartOf":{"@id":"https:\/\/www.csestack.org\/types-inheritance-cpp-program\/"},"author":{"name":"Tarshal Nimawat","@id":"https:\/\/www.csestack.org\/#\/schema\/person\/d2a8982dffb39288166553349413d218"},"headline":"5 Types of Inheritance in C++ | Detail Explained with Program","datePublished":"2019-03-15T16:58:58+00:00","dateModified":"2024-02-11T06:43:44+00:00","mainEntityOfPage":{"@id":"https:\/\/www.csestack.org\/types-inheritance-cpp-program\/"},"wordCount":529,"commentCount":0,"publisher":{"@id":"https:\/\/www.csestack.org\/#\/schema\/person\/634ef1a9c4f38b0d340c6d45fa771218"},"image":{"@id":"https:\/\/www.csestack.org\/types-inheritance-cpp-program\/#primaryimage"},"thumbnailUrl":"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Single-Inheritance.png","keywords":["cpp oops"],"articleSection":["C \/ C++","Code"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.csestack.org\/types-inheritance-cpp-program\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.csestack.org\/types-inheritance-cpp-program\/","url":"https:\/\/www.csestack.org\/types-inheritance-cpp-program\/","name":"5 Types of Inheritance in C++ | Detail Explained with Program","isPartOf":{"@id":"https:\/\/www.csestack.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.csestack.org\/types-inheritance-cpp-program\/#primaryimage"},"image":{"@id":"https:\/\/www.csestack.org\/types-inheritance-cpp-program\/#primaryimage"},"thumbnailUrl":"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Single-Inheritance.png","datePublished":"2019-03-15T16:58:58+00:00","dateModified":"2024-02-11T06:43:44+00:00","description":"What are the different types of inheritance in c++? Difference between Multilevel vs multiple inheritances explained with the program.","breadcrumb":{"@id":"https:\/\/www.csestack.org\/types-inheritance-cpp-program\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.csestack.org\/types-inheritance-cpp-program\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.csestack.org\/types-inheritance-cpp-program\/#primaryimage","url":"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Single-Inheritance.png","contentUrl":"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Single-Inheritance.png","width":292,"height":122,"caption":"Single Inheritance"},{"@type":"BreadcrumbList","@id":"https:\/\/www.csestack.org\/types-inheritance-cpp-program\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.csestack.org\/"},{"@type":"ListItem","position":2,"name":"5 Types of Inheritance in C++ | Detail Explained with Program"}]},{"@type":"WebSite","@id":"https:\/\/www.csestack.org\/#website","url":"https:\/\/www.csestack.org\/","name":"CSEstack","description":"Computer Science &amp; Programming Portal","publisher":{"@id":"https:\/\/www.csestack.org\/#\/schema\/person\/634ef1a9c4f38b0d340c6d45fa771218"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.csestack.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.csestack.org\/#\/schema\/person\/634ef1a9c4f38b0d340c6d45fa771218","name":"Aniruddha Chaudhari","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Aniruddha-Chaudhari.jpg","url":"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Aniruddha-Chaudhari.jpg","contentUrl":"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Aniruddha-Chaudhari.jpg","width":634,"height":634,"caption":"Aniruddha Chaudhari"},"logo":{"@id":"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Aniruddha-Chaudhari.jpg"},"description":"I am a Python enthusiast who loves Linux and Vim. I hold a Master of Computer Science degree from NIT Trichy and have 10 years of experience in the IT industry, focusing on the Software Development Lifecycle from Requirements Gathering, Design, Development to Deployment. I have worked at IBM, Ericsson, and NetApp, and I share my knowledge on CSEstack.org.","sameAs":["https:\/\/www.csestack.org","https:\/\/www.facebook.com\/aniruddha.ca","pythonwithani","https:\/\/www.linkedin.com\/in\/aniruddha28\/","https:\/\/x.com\/ani_chaudhari","https:\/\/www.youtube.com\/channel\/UCw0a__B0eJsvCujkSIfLTAA"]},{"@type":"Person","@id":"https:\/\/www.csestack.org\/#\/schema\/person\/d2a8982dffb39288166553349413d218","name":"Tarshal Nimawat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/6eab25d09918d2b55eb550432565aa0f07fab001482abd0d2bf5eb03832e991c?s=96&d=monsterid&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/6eab25d09918d2b55eb550432565aa0f07fab001482abd0d2bf5eb03832e991c?s=96&d=monsterid&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6eab25d09918d2b55eb550432565aa0f07fab001482abd0d2bf5eb03832e991c?s=96&d=monsterid&r=g","caption":"Tarshal Nimawat"},"description":"Tarshal is a tech-head CS undergrad, who is always on the lookout for the sharpest cutting edge techs in the business, be it Blockchain, hashgraphs or AI\/ML. With a knack for business development, negotiation and tech, she is often found educating those around her.","url":"https:\/\/www.csestack.org\/author\/tarshal\/"}]}},"_links":{"self":[{"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/posts\/4841","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/users\/37"}],"replies":[{"embeddable":true,"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/comments?post=4841"}],"version-history":[{"count":16,"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/posts\/4841\/revisions"}],"predecessor-version":[{"id":11216,"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/posts\/4841\/revisions\/11216"}],"wp:attachment":[{"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/media?parent=4841"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/categories?post=4841"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/tags?post=4841"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}