Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

Inheritance of classes, Why we need to inherit the classes

Last modified on January 3rd, 2019 at 3:28 pm

Inheritance of classes, Why we need to inherit the classes

Today, in this fresh and new article, we will cover the following topics;

  1. Inheritance of classes.
  2. Why we need to inherit the classes
  3. Syntax to inherit the class from the parent class in C++ OOP

What is the inheritance of class?

We can create child classes for a class. Child classes are called derived classes and parent classes are called base classes.

Why do we need to inherit the classes?

Lets an example of daily life.

Suppose John is a person with following properties;

  • John has resource. e.g, home, car, bank balance, and a big property.

Now John need his child for the following two reasons;

  • To support his daily work
  • To get the resources before and after his death.

So, this will leads the John to think that he should have a baby.

Similarly, in OOP, we need to create a child of the parent classes so that when we declare any variable or function in the parent class, it can be shared easily with his child class without wasting time and computer memory.

What are categories of inheritance?

There are two categories of inheritance;

  1. Single inheritance
  2. Multiple inheritances

Both of these are discussed in a separate tutorial.

Write the syntax to inherit the class from parent class?

1class child_class_name : Access_specifier Parent_class_name
3Body of the class;

Line 1: 

  • the class is a keyword to start class. after class, there is a space
  • After space we put child class name, then :
  • After: we put access specifier for class(private, protected, public)
  • After access specifier, there is one space and then parent class name.
Test Your Understandings

1.class parent_class_name : Access_specifier child_class_name is the correct syntax for creating child class? YES / NO

Answer - Click Here:
NO, it is

class child_class_name : Access_specifier Parent_class_name

2. There are two categories of inheritance?



Answer - Click Here:
1. single inheritance, 2. Multiple inheritance

Topic Covered

Inheritance of classes, Why we need to inherit the classes.

Prof. Fazal Rehman Shamil
Researcher, Publisher of International Journal Of Software Technology & Science ISSN: 2616-5325
Instructor, SEO Expert, Web Programmer and poet.
Feel free to contact.