×

C++ Programs

C++ Most popular & Searched Programs

C++ Basic I/O Programs

C++ Constructor & Destructor Programs

C++ Manipulators Programs

C++ Inheritance Programs

C++ Operator Overloading Programs

C++ File Handling Programs

C++ Bit Manipulation Programs

C++ Classes & Object Programs

C++ program to demonstrate example of single/simple inheritance

Learn about simple inheritance in C++, and implement single/simple inheritance using a C++ program.
[Last updated : March 02, 2023]

Single/Simple Inheritance in C++

In C++, the single/simple inheritance is defined as the inheritance in which a derived class is inherited from the only one base class.

This program will demonstrate example of simple inheritance in c++ programming language.

Simple Inheritance Program in C++

// C++ program to demonstrate example of
// simple inheritance

#include <iostream>
using namespace std;

// Base Class
class A {
public:
    void Afun(void);
};

// Function definiion
void A::Afun(void)
{
    cout << "I'm the body of Afun()..." << endl;
}

// Derived Class
class B : public A {
public:
    void Bfun(void);
};
// Function definition
void B::Bfun(void)
{
    cout << "I'm the body of Bfun()..." << endl;
}

int main()
{
    // Create object of derived class - class B
    B objB;
    
    // Now, we can access the function of class A (Base class)
    objB.Afun();
    objB.Bfun();
    
    return 0;
}

Output

I'm the body of Afun()...
I'm the body of Bfun()...

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.