Inheritance In C++

Share Your Love

Inheritance In C++ where you will learn how parent and child class relationships work? This is an important concept in C++.

In C++, inheritance is the process through which one object inherits all of its parent object’s properties and actions. You can reuse, extend, or change the properties and actions described in other classes in this way.

The class that inherits the members of another class is referred to as a derived class in C++, whereas the class whose members are inherited is referred to as a base class. The base class’s derived class is a customised version of the base class.

Advantage of Inheritance

You may now reuse the members of your parent class in your code means code reusability As a result, there is no need to redefine the member again in child class.

As a result, the class requires fewer codes.

Types Of Inheritance:

C++ provides five types of inheritance:

  • Single inheritance
  • Multiple inheritance
  • Hierarchical inheritance
  • Multilevel inheritance
  • Hybrid inheritance
inheritance in c
Inheritance In C++

Join Our Community Group

Join our WhatsApp Group To know more About Programming Language tips, tricks and knowledge about programming and how to start learning any programming language.

Derived Classes:

The class that is derived from the base class is referred to as a Derived class.

The Syntax of Derived class:

class derived_class_name :: visibility-mode base_class_name  
    // body of the derived class.  

Here, in the above syntax will know

derived_class_name: It is the name of the derived class.

visibility mode: The visibility mode determines whether the underlying class’s features are inherited publicly or privately.

base_class_name: The name of the base class is this.

The public members of the base class become the private members of the derived class when the base class is privately inherited by the derived class. As a result, the public members of the base class are only available by the derived class’s member functions, not by the derived class’s objects.

The public members of the base class become the public members of the derived class when the base class is openly inherited by the derived class. As a result, both the derived class’s objects and the base class’s member functions have access to the base class’s public members.

Important Note:

The default visibility mode in C++ is private.

The base class’s private members are never inherited.

Share Your Love
Avatar photo
Lingaraj Senapati

Hey There! I am Lingaraj Senapati, the Founder of My skills are Freelance, Web Developer & Designer, Corporate Trainer, Digital Marketer & Youtuber.

Articles: 429

Newsletter Updates

Enter your email address below to subscribe to our newsletter