0% found this document useful (0 votes)
54 views

Inheritance in C++ - GeeksforGeeks

The document discusses inheritance in C++, a key feature of Object Oriented Programming, explaining its syntax, modes, and types. It details how derived classes inherit properties from base classes, including access specifiers and examples of different inheritance types such as single, multiple, and hierarchical inheritance. Additionally, it covers how to access private members of base classes and the implications of different inheritance modes on member accessibility.

Uploaded by

Annie Ezekiel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Inheritance in C++ - GeeksforGeeks

The document discusses inheritance in C++, a key feature of Object Oriented Programming, explaining its syntax, modes, and types. It details how derived classes inherit properties from base classes, including access specifiers and examples of different inheritance types such as single, multiple, and hierarchical inheritance. Additionally, it covers how to access private members of base classes and the implications of different inheritance modes on member accessibility.

Uploaded by

Annie Ezekiel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks

Inheritance in C++
Last Updated : 16 Jan, 2025

The capability of a class to derive properties and characteristics from


another class is called Inheritance. Inheritance is one of the most
important features of Object Oriented Programming in C++. In this
article, we will learn about inheritance in C++, its modes and types
along with the information about how it affects different properties of
the class.

Syntax of Inheritance in C++


class derived_class_name : access-specifier base_class_name
{
// body ....
};

where,

class: keyword to create a new class


derived_class_name: name of the new class, which will inherit the
base class
access-specifier: Specifies the access mode which can be either of
private, public or protected. If neither is specified, private is taken as
default.
base-class-name: name of the base class.

Note: A derived class doesn’t inherit access to private data


members. However, it does inherit a full parent object, which
contains any private members which that class declares.

https://www.geeksforgeeks.org/inheritance-in-c/ 1/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks

Example:

class ABC : private XYZ {...} // private derivation


class ABC : public XYZ {...} // public derivation
class ABC : protected XYZ {...} // protected derivation
class ABC: XYZ {...} // private
derivation by default

To better understand inheritance and other OOP principles, enroll in our


Complete C++ Course, which breaks down inheritance, polymorphism,
and encapsulation in C++.

Examples of Inheritance in C++


The following programs demonstrate how to implement inheritance in
our C++ programs.

Example 1: Program to Demonstrate the Simple Inheritance of a


Class

// C++ program to demonstrate how to inherit a class


#include <iostream>
using namespace std;

// Base class that is to be inherited


class Parent {
public:
// base class members
int id_p;
void printID_p()
{
cout << "Base ID: " << id_p << endl;
}
};

// Sub class or derived publicly inheriting from Base


// Class(Parent)
class Child : public Parent {
public:
// derived class members
int id_c;
void printID_c()
{
cout << "Child ID: " << id_c << endl;
}
};

// main function
https://www.geeksforgeeks.org/inheritance-in-c/ 2/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks
int main()
{
// creating a child class object
Child obj1;

// An object of class child has all data members


// and member functions of class parent
// so we try accessing the parents method and data from
// the child class object.
obj1.id_p = 7;
obj1.printID_p();

// finally accessing the child class methods and data


// too
obj1.id_c = 91;
obj1.printID_c();

return 0;
}

Output

Base ID: 7
Child ID: 91

In the above program, the ‘Child’ class is publicly inherited from the
‘Parent’ class so the public data members of the class ‘Parent’ will also
be inherited by the class ‘Child’.

Example 2: Access the Inherited Members of the Base Class in


Derived Class

// C++ program to illustrate how to access the inherited


// members of the base class in derived class
#include <iostream>
using namespace std;

// Base class
class Base {
public:
// data member
int publicVar;

// member method
void display()
{
cout << "Value of publicVar: " << publicVar;
}
};

// Derived class
class Derived : public Base {
https://www.geeksforgeeks.org/inheritance-in-c/ 3/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks
public:
// Function to display inherited member
void displayMember()
{
// accessing public base class member method
display();
}

// Function to modify inherited member


void modifyMember(int pub)
{
// Directly modifying public member
publicVar = pub;
}
};

int main()
{
// Create an object of Derived class
Derived obj;

// Display the initial values of inherited member


obj.modifyMember(10);

// Display the modified values of inherited member


obj.displayMember();

return 0;
}

Output

Value of publicVar: 10

In the above example, we have accessed the public members of the


base class in the derived class but we cannot access all the base class
members directly in the derived class. It depends on the mode of
inheritance and the access specifier in the base class.

Modes of Inheritance in C++


Mode of inheritance controls the access level of the inherited members
of the base class in the derived class. In C++, there are 3 modes of
inheritance:

Public Mode
Protected Mode
Private Mode

Public Inheritance Mode


https://www.geeksforgeeks.org/inheritance-in-c/ 4/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks

If we derive a subclass from a public base class. Then the public


member of the base class will become public in the derived class and
protected members of the base class will become protected in the
derived class.

Example:

class ABC : public XYZ {...} // public derivation

Protected Inheritance Mode

If we derive a subclass from a Protected base class. Then both public


members and protected members of the base class will become
protected in the derived class.

Example:

class ABC : protected XYZ {...} // protected derivation

Private Inheritance Mode

If we derive a subclass from a Private base class. Then both public


members and protected members of the base class will become private
in the derived class. They can only be accessed by the member
functions of the derived class.

Private mode is the default mode that is applied when we don’t specify
any mode.

Example:

class ABC : private XYZ {...} // private derivation


class ABC: XYZ {...} // private
derivation by default

Note: The private members in the base class cannot be directly


accessed in the derived class, while protected and public members
can be directly accessed. To access or update the private members
of the base class in derived class, we have to use the
corresponding getter and setter functions of the base class or
declare the derived class as friend class.
https://www.geeksforgeeks.org/inheritance-in-c/ 5/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks

The below table summarizes the above three modes and shows the
access specifier of the members of the base class in the subclass when
derived in public, protected and private modes:

Examples of Modes of Inheritance

Example 1: Program to show different kinds of Inheritance


Modes and their Member Access Levels

// C++ program to show that a derived class


// doesn’t inherit access to private data members.
// However, it does inherit a full parent object.
class A {
public:
int x;

protected:
int y;

private:
int z;
};

class B : public A {
// x is public
// y is protected
// z is not accessible from B
};

class C : protected A {
// x is protected
// y is protected
// z is not accessible from C
};
https://www.geeksforgeeks.org/inheritance-in-c/ 6/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks

class D : private A // 'private' is default for classes


{
// x is private
// y is private
// z is not accessible from D
};

Example 2: Program to Access the Private Members of the Base


Class in Derived Class

// C++ program to illustrate how to access the private data


// members of the base class in derived class using public
// getter methods of base class
#include <iostream>
using namespace std;

// Base class
class Base {
private:
int privateVar;

public:
// Constructor to initialize privateVar
Base(int val): privateVar(val){}

// Public getter function to get the value of privateVar


int getPrivateVar() const { return privateVar; }

// Public setter function to set the value of privateVar


void setPrivateVar(int val) { privateVar = val; }
};

// Derived class
class Derived : public Base {
public:
// Constructor to initialize the base class
Derived(int val) : Base(val){}

// Function to display the private member of the base


// class
void displayPrivateVar()
{
// Accessing privateVar using the public member
// function of the base class
cout << "Value of privateVar in Base class: "
<< getPrivateVar() << endl;
}

// Function to modify the private member of the base


// class
void modifyPrivateVar(int val)
{
// Modifying privateVar using the public member
// function of the base class
setPrivateVar(val);
https://www.geeksforgeeks.org/inheritance-in-c/ 7/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks
}
};

int main()
{
// Create an object of Derived class
Derived obj(10);

// Display the initial value of privateVar


obj.displayPrivateVar();

// Modify the value of privateVar


obj.modifyPrivateVar(20);

// Display the modified value of privateVar


obj.displayPrivateVar();

return 0;
}

Output

Value of privateVar in Base class: 10


Value of privateVar in Base class: 20

The above program shows the method in which the private members of
the base class remain encapsulated and are only accessible through
controlled public or protected member functions.

We can also access the private members of the base class by declaring
the derived class as friend class in the base class.

// C++ program to illustrate how to access the private


// members of the base class by declaring the derived class
// as friend class in the base class
#include <iostream>
using namespace std;

// Forward declaration of the Derived class


class Derived;

// Base class
class Base {
private:
int privateVar;

public:
// Constructor to initialize privateVar
Base(int val)
: privateVar(val)
{
}

https://www.geeksforgeeks.org/inheritance-in-c/ 8/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks
// Declare Derived class as a friend
friend class Derived;
};

// Derived class
class Derived {
public:
// Function to display the private member of the base
// class
void displayPrivateVar(Base& obj)
{
// Accessing privateVar directly since Derived is a
// friend of Base
cout << "Value of privateVar in Base class: "
<< obj.privateVar << endl;
}

// Function to modify the private member of the base


// class
void modifyPrivateVar(Base& obj, int val)
{
// Modifying privateVar directly since Derived is a
// friend of Base
obj.privateVar = val;
}
};

int main()
{
// Create an object of Base class
Base baseObj(10);

// Create an object of Derived class


Derived derivedObj;

// Display the initial value of privateVar


derivedObj.displayPrivateVar(baseObj);

// Modify the value of privateVar


derivedObj.modifyPrivateVar(baseObj, 20);

// Display the modified value of privateVar


derivedObj.displayPrivateVar(baseObj);

return 0;
}

Output

Value of privateVar in Base class: 10


Value of privateVar in Base class: 20

To know more about access modes in a C++ class, refer to the article –
Access Modifiers in C++

https://www.geeksforgeeks.org/inheritance-in-c/ 9/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks

Types Of Inheritance in C++


The inheritance can be classified on the basis of the relationship
between the derived class and the base class. In C++, we have 5 types
of inheritances:

1. Single inheritance
2. Multilevel inheritance
3. Multiple inheritance
4. Hierarchical inheritance
5. Hybrid inheritance

1. Single Inheritance

In single inheritance, a class is allowed to inherit from only one class. i.e.
one base class is inherited by one derived class only.

Syntax

class subclass_name : access_mode base_class


{
// body of subclass
};

Example:

Single Inheritance

class A
{
https://www.geeksforgeeks.org/inheritance-in-c/ 10/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks

... .. ...
};
class B: public A
{
... .. ...
};

Implementation:

// C++ program to demonstrate how to implement the Single


// inheritance
#include <iostream>
using namespace std;

// base class
class Vehicle {
public:
Vehicle() { cout << "This is a Vehicle\n"; }
};

// sub class derived from a single base classes


class Car : public Vehicle {
public:
Car() { cout << "This Vehicle is Car\n"; }
};

// main function
int main()
{
// Creating object of sub class will
// invoke the constructor of base classes
Car obj;
return 0;
}

Output

This is a Vehicle
This Vehicle is Car

2. Multiple Inheritance

Multiple Inheritance is a feature of C++ where a class can inherit from


more than one class. i.e one subclass is inherited from more than one
base class.

Syntax

https://www.geeksforgeeks.org/inheritance-in-c/ 11/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks

class subclass_name : access_mode base_class1, access_mode


base_class2, ....
{
// body of subclass
};

Here, the number of base classes will be separated by a comma (‘, ‘) and
the access mode for every base class must be specified and can be
different.

Example:

Multiple Inheritance in C++

class A
{
... .. ...
};
class B
{
... .. ...
};
class C: public A, public B
{
... ... ...
};

Implementation:

// C++ program to illustrate the multiple inheritance


#i l d i t
https://www.geeksforgeeks.org/inheritance-in-c/ 12/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks
#include <iostream>
using namespace std;

// first base class


class Vehicle {
public:
Vehicle() { cout << "This is a Vehicle\n"; }
};

// second base class


class FourWheeler {
public:
FourWheeler() { cout << "This is a 4 Wheeler\n"; }
};

// sub class derived from two base classes


class Car : public Vehicle, public FourWheeler {
public:
Car() { cout << "This 4 Wheeler Vehical is a Car\n"; }
};

// main function
int main()
{
// Creating object of sub class will
// invoke the constructor of base classes.
Car obj;
return 0;
}

Output

This is a Vehicle
This is a 4 Wheeler
This 4 Wheeler Vehical is a Car

MUST READ – Multiple Inheritance in C++

3. Multilevel Inheritance

In this type of inheritance, a derived class is created from another


derived class and that derived class can be derived from a base class or
any other derived class. There can be any number of levels.

Syntax

class derived_class1: access_specifier base_class


{
... .. ...
}

https://www.geeksforgeeks.org/inheritance-in-c/ 13/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks

class derived_class2: access_specifier derived_class1


{
... .. ...
}
.....

Example:

Multilevel Inheritance in C++

class C
{
... .. ...
};
class B : public C
{
... .. ...
};
class A: public B
{
... ... ...
};

Implementation

// C++ program to implement Multilevel Inheritance


#include <iostream>
using namespace std;

// base class
class Vehicle {
public:

https://www.geeksforgeeks.org/inheritance-in-c/ 14/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks
Vehicle() { cout << "This is a Vehicle\n"; }
};

// first sub_class derived from class vehicle


class fourWheeler : public Vehicle {
public:
fourWheeler() { cout << "4 Wheeler Vehicles\n"; }
};

// sub class derived from the derived base class fourWheeler


class Car : public fourWheeler {
public:
Car() { cout << "This 4 Wheeler Vehical is a Car\n"; }
};

// main function
int main()
{
// Creating object of sub class will
// invoke the constructor of base classes.
Car obj;
return 0;
}

Output

This is a Vehicle
4 Wheeler Vehicles
This 4 Wheeler Vehical is a Car

MUST READ – Multilevel Inheritance in C++

4. Hierarchical Inheritance

In this type of inheritance, more than one subclass is inherited from a


single base class. i.e. more than one derived class is created from a
single base class.

Syntax

class derived_class1: access_specifier base_class


{
... .. ...
}
class derived_class2: access_specifier base_class
{

https://www.geeksforgeeks.org/inheritance-in-c/ 15/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks

... .. ...
}

Example:

Hierarchical Inheritance in C++

class A
{
// body of the class A.
}
class B : public A
{
// body of class B.
}
class C : public A
{
// body of class C.
}
class D : public A
{
// body of class D.
}

Implementation

// C++ program to implement Hierarchical Inheritance


#include <iostream>
using namespace std;

// base class
class Vehicle {
https://www.geeksforgeeks.org/inheritance-in-c/ 16/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks
public:
Vehicle() { cout << "This is a Vehicle\n"; }
};

// first sub class


class Car : public Vehicle {
public:
Car() { cout << "This Vehicle is Car\n"; }
};

// second sub class


class Bus : public Vehicle {
public:
Bus() { cout << "This Vehicle is Bus\n"; }
};

// main function
int main()
{
// Creating object of sub class will
// invoke the constructor of base class.
Car obj1;
Bus obj2;
return 0;
}

Output

This is a Vehicle
This Vehicle is Car
This is a Vehicle
This Vehicle is Bus

MUST READ – C++ Hierarchical Inheritance

5. Hybrid Inheritance

Hybrid Inheritance is implemented by combining more than one type of


inheritance. For example: Combining Hierarchical inheritance and
Multiple Inheritance will create hybrid inheritance in C++

There is no particular syntax of hybrid inheritance. We can just combine


two of the above inheritance types.

Example:

Below image shows one of the combinations of hierarchical and


multiple inheritances:

https://www.geeksforgeeks.org/inheritance-in-c/ 17/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks

Hybrid Inheritance in C++

class F
{
... .. ...
}
class G
{
... .. ...
}
class B : public F
{
... .. ...
}
class E : public F, public G
{
... .. ...
}
class A : public B {
... .. ...
}
class C : public B {
... .. ...
}

Implementation:

// C++ program to illustrate the implementation of Hybrid Inheritance


#include <iostream>
using namespace std;

https://www.geeksforgeeks.org/inheritance-in-c/ 18/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks

// base class
class Vehicle {
public:
Vehicle() { cout << "This is a Vehicle\n"; }
};

// base class
class Fare {
public:
Fare() { cout << "Fare of Vehicle\n"; }
};

// first sub class


class Car : public Vehicle {
public:
Car() { cout << "This Vehical is a Car\n"; }
};

// second sub class


class Bus : public Vehicle, public Fare {
public:
Bus() { cout << "This Vehicle is a Bus with Fare\n"; }
};

// main function
int main()
{
// Creating object of sub class will
// invoke the constructor of base class.
Bus obj2;
return 0;
}

Output

This is a Vehicle
Fare of Vehicle
This Vehicle is a Bus with Fare

A Special Case of Hybrid Inheritance: Multipath Inheritance

In multipath inheritance, a class is derived from two base classes and


these two base classes in turn are derived from one common base class.
An ambiguity can arise in this type of inheritance in the most derived
class. This problem is also called diamond problem due to the diamond
shape formed in the UML inheritance diagram.

MUST READ – Hybrid Inheritance in C++

Constructors and Destructors in Inheritance

https://www.geeksforgeeks.org/inheritance-in-c/ 19/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks

Constructors and Destructors are generally defined by the programmer


and if not, the compiler automatically creates them so they are present
in every class in C++. Now, the question arises what happens to the
constructor and destructor when a class is inherited by another class.

In C++ inheritance, the constructors and destructors are not inherited


by the derived class, but we can call the constructor of the base class in
derived class.

The constructors will be called by the complier in the order in which


they are inherited. It means that base class constructors will be
called first, then derived class constructors will be called.
The destructors will be called in reverse order in which the compiler
is declared.
We can also call the constructors and destructors manually in the
derived class.

Example

// C++ program to show the order of constructor call


// in single inheritance

#include <iostream>
using namespace std;

C++ C++base
// Classes and Objects C++ Polymorphism C++ Inheritance
class C++ Abstraction C++ Encapsulatio
class Parent {
public:
// base class constructor
Parent() { cout << "Inside base class" << endl; }
};

// sub class
class Child : public Parent {
public:
// sub class constructor
Child() { cout << "Inside sub class" << endl; }
};

// main function
int main()
{

// creating object of sub class


Child obj;

return 0;
}

https://www.geeksforgeeks.org/inheritance-in-c/ 20/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks

Output

Inside base class


Inside sub class

MUST READ – Order of Constructor/ Destructor Call in C++

Polymorphism in Inheritance
In Inheritance, we can redefine the base class member function in the
derived class. This type of inheritance is called Function Overriding.
Generally, in other programming languages, function overriding is
runtime polymorphism but in C++, we can do it at both runtime and
complile time. For runtime polymorphism, we have to use the virtual
functions.

Example

// C++ program to demonstrate compile time function


// overriding

#include <iostream>
using namespace std;

class Parent {
public:
void GeeksforGeeks_Print()
{
cout << "Base Function" << endl;
}
};

class Child : public Parent {


public:
void GeeksforGeeks_Print()
{
cout << "Derived Function" << endl;
}
};

int main()
{
Child Child_Derived;
Child_Derived.GeeksforGeeks_Print();
return 0;
}

https://www.geeksforgeeks.org/inheritance-in-c/ 21/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks

Output

Derived Function

MUST READ – Function Overriding in C++

Frequently Asked Questions on C++ Inheritance

Can the derived class inherit static members?

Yes, a derived class can inherit static members (such as static


variables or static functions) from the base class. However, these
members are shared across all instances of the derived class.

What are a base class and a derived class?

A base class (also called a superclass) is an existing class from


which other classes inherit properties and methods. A derived
class (also called a subclass) is a new class created by inheriting
from the base class.

What are the rules for calling a base class constructor in a


derived class?

The base class constructor can be explicitly called in the initializer


list of the derived class constructor. If not specified, the default
constructor of the base class is called automatically. If the base
class does not have a default constructor, the derived class must
explicitly call one of the base class’s constructors.

Learn C++ Online – Master everything from basics to advanced


concepts. Apply your knowledge with practical exercises and boost

https://www.geeksforgeeks.org/inheritance-in-c/ 22/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks

your skills. Take the Three 90 Challenge: finish 90% in 90 days for a
90% refund. Start now and level up your C++ programming!

Comment More info


Next Article
Placement Training Program C++ Inheritance Access

Similar Reads
Difference between Single and Multiple Inheritance in C++
Single InheritanceSingle inheritance is one in which the derived class
inherits the single base class either public, private, or protected access…
4 min read

Constructor in Multilevel Inheritance in C++


Constructor is a class member function with the same name as the class.
The main job of the constructor is to allocate memory for class objects.…
2 min read

Constructor in Multiple Inheritance in C++


Constructor is a class member function with the same name as the class.
The main job of the constructor is to allocate memory for class objects.…
2 min read

Inheritance Ambiguity in C++


Pre-requisites: Inheritance in C++, Multiple Inheritance in C++ In multiple
inheritances, when one class is derived from two or more base classes…
6 min read

C++ Multilevel Inheritance


Multilevel Inheritance in C++ is the process of deriving a class from
another derived class. When one class inherits another class it is further…
2 min read

https://www.geeksforgeeks.org/inheritance-in-c/ 23/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks

C++ Hierarchical Inheritance


Inheritance is a feature of Object-Oriented-programming in which a
derived class (child class) inherits the property (data member and memb…
4 min read

Hybrid Inheritance In C++


Before jumping into Hybrid Inheritance, let us first know what is
inheritance. Inheritance is a fundamental OOP concept in C++ that allow…
6 min read

Inheritance and Friendship in C++


Inheritance in C++: This is an OOPS concept. It allows creating classes
that are derived from other classes so that they automatically include…
2 min read

Comparison of Inheritance in C++ and Java


The purpose of inheritance is the same in C++ and Java. Inheritance is
used in both languages for reusing code and/or creating an ‘is-a’…
4 min read

C++ Inheritance Access


Prerequisites: Class-Object in C++Inheritance in C++Before learning about
Inheritance Access we need to know about access specifiers. There are…
4 min read

https://www.geeksforgeeks.org/inheritance-in-c/ 24/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks

Corporate & Communications Address:


A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Pradesh
(201305)

Registered Address:
K 061, Tower K, Gulshan Vivante
Apartment, Sector 137, Noida, Gautam
Buddh Nagar, Uttar Pradesh, 201305

Advertise with us

Company Explore
About Us Job-A-Thon Hiring Challenge
Legal Hack-A-Thon
Privacy Policy GfG Weekly Contest
Careers Offline Classes (Delhi/NCR)
In Media DSA in JAVA/C++
Contact Us Master System Design
GFG Corporate Solution Master CP
Placement Training Program GeeksforGeeks Videos
Geeks Community

Languages DSA
Python Data Structures
Java Algorithms
C++ DSA for Beginners
PHP Basic DSA Problems
GoLang DSA Roadmap
SQL DSA Interview Questions
R Language Competitive Programming
Android Tutorial

Data Science & ML Web Technologies


Data Science With Python HTML
Data Science For Beginner CSS
Machine Learning JavaScript
ML Maths TypeScript
Data Visualisation ReactJS
Pandas NextJS
NumPy NodeJs
NLP Bootstrap

https://www.geeksforgeeks.org/inheritance-in-c/ 25/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks

Deep Learning Tailwind CSS

Python Tutorial Computer Science


Python Programming Examples GATE CS Notes
Django Tutorial Operating Systems
Python Projects Computer Network
Python Tkinter Database Management System
Web Scraping Software Engineering
OpenCV Tutorial Digital Logic Design
Python Interview Question Engineering Maths

DevOps System Design


Git High Level Design
AWS Low Level Design
Docker UML Diagrams
Kubernetes Interview Guide
Azure Design Patterns
GCP OOAD
DevOps Roadmap System Design Bootcamp
Interview Questions

School Subjects Commerce


Mathematics Accountancy
Physics Business Studies
Chemistry Economics
Biology Management
Social Science HR Management
English Grammar Finance
Income Tax

Databases Preparation Corner


SQL Company-Wise Recruitment Process
MYSQL Resume Templates
PostgreSQL Aptitude Preparation
PL/SQL Puzzles
MongoDB Company-Wise Preparation
Companies
Colleges

Competitive Exams More Tutorials


JEE Advanced Software Development
UGC NET Software Testing
UPSC Product Management
SSC CGL Project Management
SBI PO Linux
SBI Clerk Excel
IBPS PO All Cheat Sheets
IBPS Clerk Recent Articles

Free Online Tools Write & Earn


https://www.geeksforgeeks.org/inheritance-in-c/ 26/27
2/23/25, 8:08 PM Inheritance in C++ - GeeksforGeeks

Typing Test Write an Article


Image Editor Improve an Article
Code Formatters Pick Topics to Write
Code Converters Share your Experiences
Currency Converter Internships
Random Number Generator
Random Password Generator

DSA/Placements Development/Testing
DSA - Self Paced Course JavaScript Full Course
DSA in JavaScript - Self Paced Course React JS Course
DSA in Python - Self Paced React Native Course
C Programming Course Online - Learn C with Data Structures Django Web Development Course
Complete Interview Preparation Complete Bootstrap Course
Master Competitive Programming Full Stack Development - [LIVE]
Core CS Subject for Interview Preparation JAVA Backend Development - [LIVE]
Mastering System Design: LLD to HLD Complete Software Testing Course [LIVE]
Tech Interview 101 - From DSA to System Design [LIVE] Android Mastery with Kotlin [LIVE]
DSA to Development [HYBRID]
Placement Preparation Crash Course [LIVE]

Machine Learning/Data Science Programming Languages


Complete Machine Learning & Data Science Program - [LIVE] C Programming with Data Structures
Data Analytics Training using Excel, SQL, Python & PowerBI - C++ Programming Course
[LIVE] Java Programming Course
Data Science Training Program - [LIVE] Python Full Course
Mastering Generative AI and ChatGPT
Data Science Course with IBM Certification

Clouds/Devops GATE
DevOps Engineering GATE CS & IT Test Series - 2025
AWS Solutions Architect Certification GATE DA Test Series 2025
Salesforce Certified Administrator Course GATE CS & IT Course - 2025
GATE DA Course 2025
GATE Rank Predictor

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved

https://www.geeksforgeeks.org/inheritance-in-c/ 27/27

You might also like