hamburger

Difference Between Base Class and Derived Class in C++

By BYJU'S Exam Prep

Updated on: September 25th, 2023

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

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.

Our Apps Playstore
POPULAR EXAMS
SSC and Bank
Other Exams
GradeStack Learning Pvt. Ltd.Windsor IT Park, Tower - A, 2nd Floor, Sector 125, Noida, Uttar Pradesh 201303 help@byjusexamprep.com
Home Practice Test Series Premium