<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>definition of inheritance - Wikitechy</title>
	<atom:link href="https://www.wikitechy.com/interview-questions/tag/definition-of-inheritance/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.wikitechy.com/interview-questions/tag/definition-of-inheritance/</link>
	<description>Interview Questions</description>
	<lastBuildDate>Mon, 13 Sep 2021 12:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.wikitechy.com/interview-questions/wp-content/uploads/2025/10/cropped-wikitechy-icon-32x32.png</url>
	<title>definition of inheritance - Wikitechy</title>
	<link>https://www.wikitechy.com/interview-questions/tag/definition-of-inheritance/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>C++ Inheritance</title>
		<link>https://www.wikitechy.com/interview-questions/cpp/c-inheritance/</link>
					<comments>https://www.wikitechy.com/interview-questions/cpp/c-inheritance/#respond</comments>
		
		<dc:creator><![CDATA[Editor]]></dc:creator>
		<pubDate>Tue, 13 Jul 2021 00:10:41 +0000</pubDate>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Accenture interview questions and answers]]></category>
		<category><![CDATA[Applied Materials interview questions and answers]]></category>
		<category><![CDATA[Atos interview questions and answers]]></category>
		<category><![CDATA[basic c++ program examples]]></category>
		<category><![CDATA[best c++ compiler]]></category>
		<category><![CDATA[best way to learn c++]]></category>
		<category><![CDATA[BMC Software interview questions and answers]]></category>
		<category><![CDATA[Bosch India Software interview questions and answers]]></category>
		<category><![CDATA[c programming examples]]></category>
		<category><![CDATA[c++ book]]></category>
		<category><![CDATA[c++ compiler download]]></category>
		<category><![CDATA[c++ compiler windows 10]]></category>
		<category><![CDATA[c++ compiler windows 7]]></category>
		<category><![CDATA[c++ derived class]]></category>
		<category><![CDATA[c++ friend functions]]></category>
		<category><![CDATA[c++ inheritance]]></category>
		<category><![CDATA[c++ inheritance example]]></category>
		<category><![CDATA[c++ inheritance example program]]></category>
		<category><![CDATA[c++ inheritance program]]></category>
		<category><![CDATA[c++ learn]]></category>
		<category><![CDATA[c++ program for multilevel inheritance]]></category>
		<category><![CDATA[c++ tutorial for beginners]]></category>
		<category><![CDATA[C++ Tutorial for Complete Beginners]]></category>
		<category><![CDATA[c++ tutorial pdf]]></category>
		<category><![CDATA[c++ tutorial point]]></category>
		<category><![CDATA[C++ Tutorials]]></category>
		<category><![CDATA[CASTING NETWORKS INDIA PVT LIMITED interview questions and answers]]></category>
		<category><![CDATA[Chetu interview questions and answers]]></category>
		<category><![CDATA[Ciena Corporation interview questions and answers]]></category>
		<category><![CDATA[define inheritance]]></category>
		<category><![CDATA[definition of inheritance]]></category>
		<category><![CDATA[Dell International Services India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[eInfochips interview questions and answers]]></category>
		<category><![CDATA[Electronics Arts Inc interview questions and answers]]></category>
		<category><![CDATA[Flipkart interview questions and answers]]></category>
		<category><![CDATA[Harman International interview questions and answers]]></category>
		<category><![CDATA[hierarchical inheritance]]></category>
		<category><![CDATA[hierarchical inheritance in c++]]></category>
		<category><![CDATA[hierarchical inheritance in c++ with example program]]></category>
		<category><![CDATA[hybrid inheritance c++ program]]></category>
		<category><![CDATA[Indecomm Global Services interview questions and answers]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[inheritance c++]]></category>
		<category><![CDATA[inheritance example]]></category>
		<category><![CDATA[inheritance in c++]]></category>
		<category><![CDATA[inheritance in c++ programming]]></category>
		<category><![CDATA[inheritance in c++ with example]]></category>
		<category><![CDATA[inheritance in c++ with example program]]></category>
		<category><![CDATA[inheritance in oop]]></category>
		<category><![CDATA[inheritance meaning]]></category>
		<category><![CDATA[intel c++ compiler]]></category>
		<category><![CDATA[khan academy c++]]></category>
		<category><![CDATA[Larsen & Toubro interview questions and answers]]></category>
		<category><![CDATA[learn c++ codecademy]]></category>
		<category><![CDATA[learn c++ pdf]]></category>
		<category><![CDATA[learn c++ programming in 21 days for beginners]]></category>
		<category><![CDATA[learn c++ reddit]]></category>
		<category><![CDATA[learn c++ the hard way]]></category>
		<category><![CDATA[Mathworks India Private Limited interview questions and answers]]></category>
		<category><![CDATA[Mavenir interview questions and answers]]></category>
		<category><![CDATA[Mphasis interview questions and answers]]></category>
		<category><![CDATA[multilevel inheritance]]></category>
		<category><![CDATA[multiple inheritance]]></category>
		<category><![CDATA[multiple inheritance c++ example]]></category>
		<category><![CDATA[multiple inheritance c++ program]]></category>
		<category><![CDATA[multiple inheritance in c++ example]]></category>
		<category><![CDATA[NetApp interview questions and answers]]></category>
		<category><![CDATA[Online C/C++ Tutorial Academy]]></category>
		<category><![CDATA[online turbo c++ compiler]]></category>
		<category><![CDATA[Oracle Corporation interview questions and answers]]></category>
		<category><![CDATA[PeopleStrong interview questions and answers]]></category>
		<category><![CDATA[Philips Software Centre Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[SRM Technologies interview questions and answers]]></category>
		<category><![CDATA[Symphony Teleca interview questions and answers]]></category>
		<category><![CDATA[Tech Mahindra interview questions and answers]]></category>
		<category><![CDATA[Tecnotree interview questions and answers]]></category>
		<category><![CDATA[types of inheritance]]></category>
		<category><![CDATA[types of inheritance in c++ with example program]]></category>
		<category><![CDATA[virtual inheritance]]></category>
		<category><![CDATA[what is inheritance]]></category>
		<category><![CDATA[what is inheritance in cpp]]></category>
		<category><![CDATA[Wipro Infotech interview questions and answers]]></category>
		<category><![CDATA[Wipro interview questions and answers]]></category>
		<category><![CDATA[Yash Technologies interview questions and answers]]></category>
		<guid isPermaLink="false">https://www.wikitechy.com/interview-questions/?p=404</guid>

					<description><![CDATA[Answer : Inheritance is one of the key features of Object-oriented programming...]]></description>
										<content:encoded><![CDATA[<div class="ImageContent">
<div class="hddn" style="text-align: justify;"><a href="https://cdn.wikitechy.com/interview-questions/c++/c++-inheritance.gif"><img decoding="async" class="img-responsive center-block" src="https://www.wikitechy.com/tutorials/c++/img/c++-images/c++-inheritance.gif" alt=" c++-inheritance" /></a></div>
<div>
<div class="ImageContent" style="text-align: justify;">
<div class="hddn"><a href="https://cdn.wikitechy.com/interview-questions/c++/c++-inheritance.jpg"><img decoding="async" class="img-responsive center-block aligncenter" src="https://www.wikitechy.com/tutorials/c++/img/c++-images/c++-inheritance.jpg" alt=" c++ inheritance" /></a></div>
</div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="inheritance-in-c" class="color-pink">Inheritance in C++</h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>Inheritance is one of the key features of Object-oriented programming in C++. It allows user to create a new class (derived class) from an existing class(base class).</li>
<li>The derived class inherits all the features from the base class and can have additional features of its own</li>
</ul>
</div>
</div>
<div class="ImageContent" style="text-align: justify;">
<div class="hddn"><img decoding="async" class="img-responsive center-block aligncenter" src="https://www.wikitechy.com/tutorials/c++/img/c++-images/multiple-inheritance-1.gif" alt="learn c++ tutorials - inheritance in c++" /></div>
</div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="base-derived-classes" class="color-green">Base &amp; Derived Classes</h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>A class can be derived from more than one classes, which means it can inherit data and functions from multiple base classes.</li>
<li>To define a derived class, we use a class derivation list to specify the base class(es).</li>
<li>A class derivation list names one or more base classes and has the form:</li>
</ul>
</div>
</div>
<div class="Output" style="text-align: justify;">
<div class="hddn">
<figure class="highlight">
<pre><code class="c++ hljs typescript" data-lang="c++"><span class="nt"><span class="hljs-keyword">class</span> derived-<span class="hljs-keyword">class</span>: access-specifier base-<span class="hljs-keyword">class</span></span></code></pre>
</figure>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>Where access-specifier is one of public, protected, or private, and base-class is the name of a previously defined class.</li>
<li>If the access-specifier is not used, then it is private by default.</li>
</ul>
</div>
</div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="why-inheritance-should-be-used" class="color-pink">Why inheritance should be used?</h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>Suppose, in your game, you want three characters &#8211; a maths teacher, a footballer and a businessman.</li>
<li>Since, all of the characters are persons, they can walk and talk. However, they also have some special skills. A maths teacher can teach maths, a footballer can play football and a businessman can run a business.</li>
<li>You can individually create three classes who can walk, talk and perform their special skill as shown in the figure below.</li>
</ul>
</div>
</div>
<div class="ImageContent" style="text-align: justify;">
<div class="hddn"><a href="https://cdn.wikitechy.com/interview-questions/c++/c++-inherit.jpg"><img decoding="async" class="img-responsive center-block aligncenter" src="https://www.wikitechy.com/tutorials/c++/img/c++-images/c++-inherit.jpg" alt=" c++ inheritances" /></a></div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>In each of the classes, you would be copying the same code for walk and talk for each character.</li>
<li>If you want to add a new feature &#8211; eat, you need to implement the same code for each character. This can easily become error prone (when copying) and duplicate codes.</li>
<li>It&#8217;d be a lot easier if we had a Person class with basic features like talk, walk, eat, sleep, and add special skills to those features as per our characters. This is done using inheritance.</li>
</ul>
</div>
</div>
<div class="ImageContent" style="text-align: justify;">
<div class="hddn"><a href="https://cdn.wikitechy.com/interview-questions/c++/c+ineritance-multiple.jpg"><img decoding="async" class="img-responsive center-block" src="https://www.wikitechy.com/tutorials/c++/img/c++-images/c+ineritance-multiple.jpg" alt=" c++ inheritances multiple" /></a></div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>Using inheritance, now you don&#8217;t implement the same code for walk and talk for each class. You just need to inherit them.</li>
<li>This makes your code cleaner, understandable and extendable</li>
</ul>
</div>
</div>
<div class="TextHeading">
<div class="hddn">
<h6 id="learn-c-c-tutorial-c-programming-c-language-cplusplus" style="text-align: justify;">Learn C++ , C++ Tutorial , C++ programming &#8211; C++ Language -Cplusplus</h6>
<h5 id="implementation-of-inheritance-in-c-programming" class="color-blue" style="text-align: justify;">Implementation of Inheritance in C++ Programming</h5>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-cpp code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-cpp code-embed-code">class Person <br/>{<br/>  ... .. ...<br/>};<br/>class MathsTeacher : public Person <br/>{<br/>  ... .. ...<br/>};<br/>class Footballer : public Person<br/>{<br/>  .... .. ...<br/>};</code></pre> </div>
<ul style="text-align: justify;">
<li>In the above example, class Person is a base class and classes MathsTeacher andFootballer are the derived from Person.</li>
<li>The derived class appears with the declaration of a class followed by a colon, the keywordpublic and the name of base class from which it is derived.</li>
<li>Since, MathsTeacher and Footballer are derived from Person, all data member and member function of Person can be accessible from them</li>
</ul>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="example-inheritance-in-c-programming" class="color-red">Example: Inheritance in C++ Programming</h2>
</div>
</div>
<div class="Content">
<div class="hddn">
<ul style="text-align: justify;">
<li>Create game characters using the concept of inheritance.</li>
</ul>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-cpp code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-cpp code-embed-code">#include &lt;iostream&gt;<br/>using namespace std;<br/><br/>class Person<br/>{<br/>     public:<br/>        string profession;<br/>        int age;<br/><br/>        Person(): profession(&quot;unemployed&quot;), age(16) { }<br/>        void display()<br/>        {<br/>             cout &lt;&lt; &quot;My profession is: &quot; &lt;&lt; profession &lt;&lt; endl;<br/>             cout &lt;&lt; &quot;My age is: &quot; &lt;&lt; age &lt;&lt; endl;<br/>             walk();<br/>             talk();<br/>        }<br/>        void walk() { cout &lt;&lt; &quot;I can walk.&quot; &lt;&lt; endl; }<br/>        void talk() { cout &lt;&lt; &quot;I can talk.&quot; &lt;&lt; endl; }<br/>};<br/><br/>// MathsTeacher class is derived from base class Person.<br/>class MathsTeacher : public Person<br/>{<br/>    public:<br/>       void teachMaths() { cout &lt;&lt; &quot;I can teach Maths.&quot; &lt;&lt; endl; }<br/>};<br/><br/>// Footballer class is derived from base class Person.<br/>class Footballer : public Person<br/>{<br/>    public:<br/>       void playFootball() { cout &lt;&lt; &quot;I can play Football.&quot; &lt;&lt; endl; }<br/>};<br/><br/>int main()<br/>{<br/>     MathsTeacher teacher;<br/>     teacher.profession = &quot;Teacher&quot;;<br/>     teacher.age = 23;<br/>     teacher.display();<br/>     teacher.teachMaths();<br/><br/>     Footballer footballer;<br/>     footballer.profession = &quot;Footballer&quot;;<br/>     footballer.age = 19;<br/>     footballer.display();<br/>     footballer.playFootball();<br/><br/>     return 0;<br/>}</code></pre> </div>
<h2 id="output" class="color-purple" style="text-align: justify;">Output</h2>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-cpp code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-cpp code-embed-code">My profession is: Teacher<br/>My age is: 23<br/>I can walk.<br/>I can talk.<br/>I can teach Maths.<br/>My profession is: Footballer<br/>My age is: 19<br/>I can walk.<br/>I can talk.<br/>I can play Football.</code></pre> </div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>In this program, Person is a base class, while MathsTeacher and Footballer are derived from Person</li>
<li>Person class has two data members &#8211; profession and age. It also has two member functions &#8211; walk() and talk().</li>
<li>Both MathsTeacher and Footballer can access all data members and member functions of Person.</li>
<li>However, MathsTeacher and Footballer have their own member functions as well:teachMaths() and playFootball() respectively. These functions are only accessed by their own class.</li>
<li>In the main() function, a new MathsTeacher object teacher is created.</li>
<li>Since, it has access to Person&#8217;s data members, profession and age of teacher is set. This data is displayed using the display() function defined in the Person class. Also, the teachMaths() function is called, defined in the MathsTeacher class.</li>
<li>Likewise, a new Footballer object footballer is also created. It has access to Person&#8217;s data members as well, which is displayed by invoking the display() function. The playFootball() function only accessible by the footballer is called then after.</li>
</ul>
</div>
</div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="access-specifiers-in-inheritance" class="color-orange">Access specifiers in Inheritance</h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>When creating a derived class from a base class, you can use different access specifiers to inherit the data members of the base class.</li>
<li>These can be public, protected or private.</li>
<li>In the above example, the base class Person has been inherited public-ly by MathsTeacherand Footballer.</li>
</ul>
</div>
</div>
<div class="TextHeading">
<div class="hddn">
<h2 id="member-function-overriding-in-inheritance" class="color-green" style="text-align: justify;">Member Function Overriding in Inheritance</h2>
<ul style="text-align: justify;">
<li>Suppose, base class and derived class have member functions with same name and arguments.</li>
<li>If you create an object of the derived class and try to access that member function, the member function in derived class is only invoked.</li>
<li>The member function of derived class overrides the member function of base class.</li>
</ul>
<p style="text-align: justify;">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/cpp/c-inheritance/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
