Inheritance in C++

44 sec read Basic

What is inheritance

Inheritance is the most important and useful feature of an Object oriented language. Inheritance is a kind of parent and child relationship or Base Class and Derived Class hierarchy.

Suppose there is a class named as Car. Now we know that every car has the brake system, Gear System, accelerator etc in common. Now think for a while, as a programmer if you have to write the functionality of break, gear system, acceleartor each time for different cars. How painful will it be? So that's why Inheritance came into existence. Inheritance allows you to use a class which includes common features plus you can add your own features into it. This can be done by Derived Class


Syntax :-


class Name : visibilityMode BaseClassName
Data members
Member functions

visibilityMode indicates the visibility of base class member in derived class. It can be private , public or protected.

Example :-

using namespace std;
class Shape {
		 void area() {
			cout << "Base Class" << endl;
class Circle : public Shape {
	public :
	void extraFeatureMethod()
		cout<<"Add Extra Fetaure of circle here"<

Output :-

Base Class
Add Extra Fetaure of circle here

Circle class is derived class of class Shape with public visibility modifier. Now circle is called as derived class or child class and Shape class is called as super class or parent class. All the member functions in shape class like an area() method is available in derived class. Plus we added one extraFeatureMethod in derived class.

How was the tutorial? Nice. Right?

Deep Concept videos to crack the highly-piad interviews.

Chekout out our Youtube Channel to get detailed video content on important topics in interviews.

What is your Interview Score?

Test your skillset with the curated questions created by experts around the globe.

Book a free test slot. Now !.

It usually takes 30 mins for an online test and this test will be MCQ based. Get detailed analytics based on your test and recommedations with personalised roadmaps.

Book a test slot. Now!

Have questions about the trial coding class?

Chat with our experts to discuss

Connect on WhatsApp

Recommended tutorials

#online compiler for c     #python for programming    

#dfs and bfs algorithm     #programming with c language

#storageclass in C    #listcomprehension in python