{"id":81413,"date":"2021-07-09T09:00:12","date_gmt":"2021-07-09T03:30:12","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=81413"},"modified":"2021-07-09T09:00:12","modified_gmt":"2021-07-09T03:30:12","slug":"inheritance-in-cpp","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/inheritance-in-cpp\/","title":{"rendered":"Inheritance in C++"},"content":{"rendered":"<p>One of the most important features of Object-Oriented Programming is Inheritance. In this article, we will learn all about inheritance in C++.<\/p>\n<h3>What is Inheritance in C++<\/h3>\n<p>Inheritance refers to the ability of a class to derive features and traits from another class.<\/p>\n<p><strong>Base Class:<\/strong> The class whose features are inherited is called the super class or the base class or the parent class.<\/p>\n<p><strong>Derived Class:<\/strong> The class that inherits the features is called the sub class or the derived class or the child class.<\/p>\n<p>Let\u2019s consider classes of computer science engineers and electrical engineers. Both of these are inherited from a class of engineers. This is a real life example of inheritance.<\/p>\n<p>Inheritance implements an is-a relationship. For example, a boy is a human, a lily is a flower, etc.<\/p>\n<h3>Use of Inheritance in C++<\/h3>\n<p>If there are three sections A, B and C in a school, the classes for these sections will have the same functions like students(), timetable(), classteacher(), etc. Without inheritance, we will have to define these functions in all three classes. Thus, writing the same code thrice.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Without-Inheritance.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81718\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Without-Inheritance.jpg\" alt=\"Programming without Inheritance\" width=\"778\" height=\"407\" \/><\/a><\/p>\n<p>As a solution, we use inheritance which<\/p>\n<ul>\n<li>Increases the reusability of code<\/li>\n<li>Eliminates duplication<\/li>\n<li>Increases the reliability of code as it provides a definite structure to our programs<\/li>\n<li>Brings transitive nature<\/li>\n<\/ul>\n<p>Hence, our program becomes simple by creating a base class school.<br \/>\n<a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/With-Inheritance.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81719\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/With-Inheritance.jpg\" alt=\"Programming with inheritance\" width=\"644\" height=\"386\" \/><\/a><\/p>\n<h3>Implementation of Inheritance in C++<\/h3>\n<p><strong>Syntax to create a derived class:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class derivedclass_name : access_specifier baseclass_name {\n\/\/body of derived class\n};<\/pre>\n<p>Here,<\/p>\n<ul>\n<li>derivedclass_name is the name given to the derived class<\/li>\n<li>baseclass_name is the name of the base class<\/li>\n<li>access_specifier specifies the mode of inheritance. It is public, private or protected.<\/li>\n<\/ul>\n<h3>Access Control in C++<\/h3>\n<p>It is not possible for a derived class to directly access private members of its base class. However, it gets a complete object of base class which contains the private members. The derived class can also access private members of the base class through its public and protected members.<\/p>\n<p>A derived class does not inherit<\/p>\n<ul>\n<li>Constructors and destructors of the base class<\/li>\n<li>Friend classes and friend functions of the base class<\/li>\n<li>Overloaded operators of the base class<\/li>\n<\/ul>\n<h3>Modes of Inheritance in C++<\/h3>\n<h4>1. Public inheritance in C++<\/h4>\n<p>If a derived class is inherited from a public base class, the base class\u2019s public members become public and protected members become protected in the derived class.<\/p>\n<h4>2. Protected Inheritance in C++<\/h4>\n<p>If we inherit a derived class from a protected base class, the base class\u2019s public as well as protected members become protected in the derived class.<\/p>\n<h4>3. Private Inheritance in C++<\/h4>\n<p>If a derived class is inherited from a private base class, both public and protected members of the base class become private in the derived class.<\/p>\n<p>For every mode of inheritance, the table below shows the access control of base class members in a derived class.<\/p>\n<table style=\"height: 295px\" width=\"610\">\n<tbody>\n<tr>\n<td rowspan=\"2\"><strong>Base Class Member<\/strong><\/td>\n<td colspan=\"3\"><strong>Mode of Inheritance<\/strong><\/td>\n<\/tr>\n<tr>\n<td><strong>Public<\/strong><\/td>\n<td><strong>Protected<\/strong><\/td>\n<td><strong>Private<\/strong><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Public<\/span><\/td>\n<td><span style=\"font-weight: 400\">Public<\/span><\/td>\n<td><span style=\"font-weight: 400\">Protected<\/span><\/td>\n<td><span style=\"font-weight: 400\">Private<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Protected<\/span><\/td>\n<td><span style=\"font-weight: 400\">Protected<\/span><\/td>\n<td><span style=\"font-weight: 400\">Protected<\/span><\/td>\n<td><span style=\"font-weight: 400\">Private<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Private<\/span><\/td>\n<td><span style=\"font-weight: 400\">Private<\/span><\/td>\n<td><span style=\"font-weight: 400\">Private<\/span><\/td>\n<td><span style=\"font-weight: 400\">Private<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Types of Inheritance in C++<\/h3>\n<p>There are 5 types of C++ Inheritance:<\/p>\n<h4>1. Single Inheritance in C++<\/h4>\n<p>In this type of inheritance, there is only one derived class inherited from one base class.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Single-inheritance.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81720\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Single-inheritance.jpg\" alt=\"Single inheritance in C++\" width=\"386\" height=\"217\" \/><\/a><\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class base {\n\/\/Body of the base class\n};\nclass derived : access_specifier base {\n\/\/Body of the derived class\n};\n<\/pre>\n<p><strong>Example of Single Inheritance in C++<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;iostream&gt;\nusing namespace std;\n\nclass Animal {\n    public:\n        void fun1() {\n            cout&lt;&lt;\"I am an animal\"&lt;&lt;endl;\n        }\n};\n\nclass Dog : public Animal {\n    public:\n        void fun2() {\n            cout&lt;&lt;\"I am a dog\"&lt;&lt;endl;\n        }\n};\n\nint main() {\n  Dog obj;\n  obj.fun1();\n  obj.fun2();\n  return 0;\n}\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">I am an animal<br \/>\nI am a dog<\/div>\n<h4>2. Multiple Inheritance in C++<\/h4>\n<p>In this type of inheritance, one derived class inherits from more than one base class.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Multiple-Inheritance.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81721\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Multiple-Inheritance.jpg\" alt=\"Multiple Inheritance in C++\" width=\"501\" height=\"290\" \/><\/a><\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class base1 {\n  \/\/body\n};\nclass base2 {\n  \/\/body\n};\n.\n.\n.\nclass derived : access_specifier base1, access_specifier base2, ... {\n  \/\/body of the derived class\n};\n<\/pre>\n<p><strong>Example of Multiple Inheritance in C++<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;iostream&gt;\nusing namespace std;\n\nclass A {\n    protected:\n    int a;\n    public:\n    void seta(int x) {\n        a = x;\n    }\n};\n\nclass B {\n    protected:\n    int b;\n    public:\n    void setb(int y) {\n        b = y;\n    }\n};\nclass C : public A, public B {\n    public:\n    int add() {\n        cout&lt;&lt;\"Addition of two numbers = \"&lt;&lt;a+b;\n    }\n};\n\nint main() {\n  C obj;\n  obj.seta(4);\n  obj.setb(9);\n  obj.add();\n  return 0;\n}\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Addition of two numbers = 13<\/div>\n<h4>3. Multilevel Inheritance in C++<\/h4>\n<p>A derived class inherits from another derived class in this type of inheritance.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Multilevel-Inheritance.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81722\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Multilevel-Inheritance.jpg\" alt=\"Multilevel Inheritance in C++\" width=\"486\" height=\"290\" \/><\/a><\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class C {\t\t\/\/Base Class\n  \/\/body\n};\nclass B : access_specifier C {\t\t\t\/\/Derived from C\n  \/\/body\n};\nclass A : access_specifier B {\t\t\t\/\/Derived from B\n  \/\/body\n};\n<\/pre>\n<p><strong>Example of Multilevel Inheritance in C++<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;iostream&gt;\nusing namespace std;\n\nclass Animal {\n    public:\n    void fun1() {\n        cout&lt;&lt;\"Animal\"&lt;&lt;endl;\n    }\n};\n\nclass PetAnimal : public Animal {\n    public:\n    void fun2() {\n        cout&lt;&lt;\"Pet animal\"&lt;&lt;endl;\n    }\n};\n\nclass Dog : public PetAnimal {\n    public:\n    void fun3() {\n          fun1();\n        fun2();\n        cout&lt;&lt;\"Dog\"&lt;&lt;endl;\n    }\n};\n\nint main() {\n  Dog obj;\n  obj.fun3();\n  return 0;\n}\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Animal<br \/>\nPet animal<br \/>\nDog<\/div>\n<h4>4. Hierarchical Inheritance in C++<\/h4>\n<p>Multiple derived classes are inherited from a single base class in this type of inheritance.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Hierarchical-Inheritance.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81723\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Hierarchical-Inheritance.jpg\" alt=\"Hierarchical Inheritance in C++\" width=\"572\" height=\"281\" \/><\/a><\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class base {\n  \/\/body\n};\nclass derived1 : access_specifier base {\n  \/\/body;\n};\nclass derived2 : access_specifier base {\n  \/\/body;\n};\n<\/pre>\n<p><strong>Example of Hierarchical Inheritance in C++<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;iostream&gt;\nusing namespace std;\n\nclass Values {\n    protected:\n    double a, b;\n    public:\n    void initialize(double x, double y) {\n        a = x;\n        b = y;\n    }\n};\n\nclass A : public Values {\n    public:\n    void add() {\n        cout&lt;&lt;\"addition = \"&lt;&lt;a+b&lt;&lt;endl;\n    }\n};\n\nclass B : public Values {\n    public:\n    void subtract() {\n        cout&lt;&lt;\"subtraction = \"&lt;&lt;a-b&lt;&lt;endl;\n    }\n};\n\nint main() {\n  A obj1;\n  B obj2;\n  obj1.initialize(4.5,8.7);\n  obj1.add();\n  obj2.initialize(3.6,11);\n  obj2.subtract();\n  return 0;\n}\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">addition = 13.2<br \/>\nsubtraction = -7.4<\/div>\n<h4>5. Hybrid Inheritance in C++<\/h4>\n<p>Hybrid inheritance is the combination of two or more types of inheritance. We can make various combinations in hybrid inheritance.<\/p>\n<p>For example, a combination of hierarchical and multiple inheritance (commonly called multipath inheritance) as shown in the image below.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Hybrid-Inheritance.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81724\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/Hybrid-Inheritance.jpg\" alt=\"Hybrid Inheritance in C++\" width=\"358\" height=\"322\" \/><\/a><\/p>\n<p><strong>Example of Hybrid Inheritance in C++<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;iostream&gt;\nusing namespace std;\n\nclass A {\n    protected:\n    float a;\n    public:\n    void seta(float n1) {\n        a = n1;\n    }\n};\n\nclass B : public A {\n    public:\n    void modifyA() {\n        a\/=2;\n    }\n};\n\nclass C {\n    protected:\n    float c;\n    public:\n    void setc(float n2) {\n        c = n2;\n    }\n};\n\nclass D : public B, public C {\n    public:\n    float modify() {\n        modifyA();\n        cout&lt;&lt;\"Result = \"&lt;&lt;a*c;\n    }\n};\n\nint main() {\n  D obj;\n  obj.seta(15.6);\n  obj.setc(9.7);\n  obj.modify();\n  return 0;\n}\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Result = 75.66<\/div>\n<h3>Avoiding Ambiguity in Inheritance<\/h3>\n<p>In some cases of inheritance, the compiler faces ambiguity. An example of such a case is<\/p>\n<p><strong>Example of Ambiguity in Inheritance<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;iostream&gt;\nusing namespace std;\n\nclass A {\n    protected:\n    int a;\n};\nclass B : public A {\n\n};\nclass C : public A {\n\n};\nclass D : public B, public C {\n    public:\n    void fun() {\n        a=7;       \/\/ambiguity\n    } \n    void display() {\n        cout&lt;&lt;\"a from B = \"&lt;&lt;a&lt;&lt;endl;\n        cout&lt;&lt;\"a from C = \"&lt;&lt;a&lt;&lt;endl; \n    }\n};\nint main() {\n  D obj;\n  obj.fun();\n  obj.display();\n  return 0;\n}\n<\/pre>\n<p>We get a compilation error stating reference to \u2018a\u2019 is ambiguous.<\/p>\n<p>This happened because class D has two copies of variable a, one via class B and other via class C.<\/p>\n<p>We can avoid such ambiguity in two ways.<\/p>\n<h4>1. Using scope resolution operator (::)<\/h4>\n<p><strong>Example of avoiding ambiguity using scope resolution operator (::)<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;iostream&gt;\nusing namespace std;\n\nclass A {\n    protected:\n    int a;\n};\nclass B : public A {\n\n};\nclass C : public A {\n\n};\nclass D : public B, public C {\n    public:\n    void fun() {\n        B::a=7;\n        C::a=10;\n    }\n    void display() {\n        cout&lt;&lt;\"a from B = \"&lt;&lt;B::a&lt;&lt;endl;\n        cout&lt;&lt;\"a from C = \"&lt;&lt;C::a&lt;&lt;endl;        \n    }\n};\nint main() {\n  D obj;\n  obj.fun();\n  obj.display();\n  return 0;\n}\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">a from B = 7<br \/>\na from C = 10<\/div>\n<p>Note that here, class D has two copies of class A.<\/p>\n<h4>2. Using the virtual base class<\/h4>\n<p><strong>Example of avoiding ambiguity using virtual base class<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;iostream&gt;\nusing namespace std;\n\nclass A {\n    protected:\n    int a;\n};\nclass B : virtual public A {\n\n};\nclass C : virtual public A {\n\n};\nclass D : public B, public C {\n    public:\n    void fun() {\n        a = 7;\n    }\n    void display() {\n        cout&lt;&lt;\"a from B = \"&lt;&lt;a&lt;&lt;endl;\n        cout&lt;&lt;\"a from C = \"&lt;&lt;a&lt;&lt;endl;        \n    }\n};\nint main() {\n  D obj;\n  obj.fun();\n  obj.display();\n  return 0;\n}\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">a from B = 7<br \/>\na from C = 7<\/div>\n<p>Here, class D contains a single copy of class A. This implies that both class B and C share the same copy of variable a.<\/p>\n<h3>Summary<\/h3>\n<p>This article covers the concept of inheritance, which is one of the most significant features of OOPs. We learnt why it is important. Then, we covered how to implement inheritance in C++.<\/p>\n<p>There are 5 types of inheritance namely, single, multiple, multilevel, hierarchical and hybrid inheritance. We learnt about all these types of inheritance with suitable examples. We may get a compilation error due to ambiguity in some cases of inheritance. This can be solved using scope resolution operator (::) or virtual base class.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the most important features of Object-Oriented Programming is Inheritance. In this article, we will learn all about inheritance in C++. What is Inheritance in C++ Inheritance refers to the ability of a&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":81716,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3405],"tags":[3701,3702,3703,3704,3705,3706],"class_list":["post-81413","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cpp","tag-hierarchical-inheritance-in-c","tag-hybrid-inheritance-in-c","tag-inheritance-in-c","tag-multilevel-inheritance-in-c","tag-multiple-inheritance-in-c","tag-single-inheritance-in-c"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Inheritance in C++ - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn all about Inheritance in C++ which refers to the ability of a class to derive features and traits from another class. learn its types.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/inheritance-in-cpp\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Inheritance in C++ - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn all about Inheritance in C++ which refers to the ability of a class to derive features and traits from another class. learn its types.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/inheritance-in-cpp\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-09T03:30:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Inheritance-in-C.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Inheritance in C++ - TechVidvan","description":"Learn all about Inheritance in C++ which refers to the ability of a class to derive features and traits from another class. learn its types.","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:\/\/techvidvan.com\/tutorials\/inheritance-in-cpp\/","og_locale":"en_US","og_type":"article","og_title":"Inheritance in C++ - TechVidvan","og_description":"Learn all about Inheritance in C++ which refers to the ability of a class to derive features and traits from another class. learn its types.","og_url":"https:\/\/techvidvan.com\/tutorials\/inheritance-in-cpp\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-07-09T03:30:12+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Inheritance-in-C.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/inheritance-in-cpp\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/inheritance-in-cpp\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Inheritance in C++","datePublished":"2021-07-09T03:30:12+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/inheritance-in-cpp\/"},"wordCount":902,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/inheritance-in-cpp\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Inheritance-in-C.jpg","keywords":["Hierarchical Inheritance in C++","Hybrid Inheritance in C++","Inheritance in C++","Multilevel Inheritance in C++","Multiple Inheritance in C++","Single Inheritance in C++"],"articleSection":["C++ Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/inheritance-in-cpp\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/inheritance-in-cpp\/","url":"https:\/\/techvidvan.com\/tutorials\/inheritance-in-cpp\/","name":"Inheritance in C++ - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/inheritance-in-cpp\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/inheritance-in-cpp\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Inheritance-in-C.jpg","datePublished":"2021-07-09T03:30:12+00:00","description":"Learn all about Inheritance in C++ which refers to the ability of a class to derive features and traits from another class. learn its types.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/inheritance-in-cpp\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/inheritance-in-cpp\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/inheritance-in-cpp\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Inheritance-in-C.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/Inheritance-in-C.jpg","width":1200,"height":628,"caption":"Inheritance in C++"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/inheritance-in-cpp\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Inheritance in C++"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/81413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=81413"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/81413\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/81716"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=81413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=81413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=81413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}