Difference Between Base Class and Derived Class in C++

By Anjnee Bhatnagar|Updated : September 21st, 2022

In object-oriented paradigm or C++ programming, we have two very useful and elementary class types: base and derived. The difference between the base class and a derived class in C++ is that a base class is defined as any existing class used in the program, whereas a derived class derives its characteristics from the base class or inherits them from it.

This article will show the difference between the base and derived classes in C++. To begin with, first, let us understand the meaning of a base class individually and a derived class. After understanding the meaning of these two categories of classes, we will learn the major difference between the base class and derived class.

Difference Between Base Class and Derived Class in C++ PDF

Download Formulas for GATE Computer Science Engineering - Algorithms

Difference between base class and derived class in C++

Difference Between Base Class and Derived Class in C++

We will see the individual meaning of base class and derived class, after understanding the difference between base class and derived class in C++. The major difference between base class and derived class in object-oriented programming are listed in the table below. You can also check the difference between procedural and object-oriented programming.

Download Formulas for GATE Computer Science Engineering - Digital Logic

Key Difference Between Base Class and Derived Class

Base Class

Derived Class

It is defined as the class from which properties are acquired.

It is defined as the class which acquires the properties.

Cannot acquire or inherit properties from any other class.

Can inherit properties and methods from the base class.

Also called Parent class or Superclass.

Also called Child class or Subclass.

What is Base Class in C++?

A base class is any existing class from which other classes can be derived in C++ or object-oriented programming. A base class is sometimes alternately called a parent class or a superclass. Other non-base classes can acquire the members and functions of a base class.

The syntax of the base class is the same as any other regular class syntax. The syntax is as follows:

class base_class

{

//class_members

//class_member_functions

}

Note: C++ is a case-sensitive language, so the keyword class is always in lower case; however, we can use any notation to name a class. In the above example, snake notation has been used. One can also use camel notation for the class name.

Download Formulas for GATE Computer Science Engineering - Computer Organization & Architecture

What is Derived Class in C++?

A derived class in object-oriented programming is defined as one that can inherit or acquire properties of an already existing class called the base class. The base class can be easily accessed by a derived class. One of the striking difference between base class and derived class in C++ is that a derived class provides more functionality with respect to the base class.

Derived classes use access modifiers to access the members of the base class. If the modifier is not specified, then by default, the functionality of the private access modifier is applied to the derived class. The syntax for creating a derived class from the base class is as follows:

class base_class

{

//class_members

//class_member_functions

}

class derived_class: public base_class

{

//class_members

//class_member_functions

}

Note: The derived classes make use of access modifiers. Access modifiers are used to provide accessibility to the members of the class. There are three types of access modifiers in C++, they are:

  • Public
  • Private
  • Protected

Further, let us see some other related articles.

Comments

write a comment

FAQs on Difference Between Base Class and Derived Class

  • The difference between base class and derived class in C++ is that a base class currently exists in the program, whereas a derived class may acquire the members and methods of a base class.

  • In C++, to have access to a member or a method, we make use of access modifiers, especially in the derived class access modifiers are used to have access to the base class. There are majorly three types of access modifiers available in C++, they are:

    • Private
    • Public
    • Protected
  • The difference between base class and derived class in C++ in terms of functionality is that a derived class provides more and better functionality in contrast to a base class. A derived class consists of members and methods of its own in addition to the members and methods of the base class, thereby providing more features to the programmer.

  • If the access modifier is not specified by the user in the derived class, then by default private access modifier is implemented on the base class. It is, therefore, a good practice to specify the access modifier before using a base class to acquire properties.

  • The difference between base and derived class in terms of inheriting a property or member is that a base class can never inherit the properties, members, and methods of any other class. At the same time, a derived or Subclass can inherit properties, members, and methods of its base class.

Follow us for latest updates