Users Online
· Guests Online: 42
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Newest Threads
No Threads created
Hottest Threads
No Threads created
Latest Articles
Articles Hierarchy
Multiple Inheritance Program in C++
Multiple Inheritance Program in C++
This C++ program illustrates multiple inheritance. The concept of multiple inheritance is used when derivation is to be done from two or more classes. The features available in the classes from which derived class is to be constructed are available in the derived class.
Here is the source code of the C++ program which illustrates multiple inheritance. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
-
/*
-
* C++ Program to illustrate multiple inheritance
-
*/
-
#include <iostream>
-
using namespace std;
-
-
class A {
-
int i;
-
public:
-
A() : i(1) {
-
cout << "A's constructor\n";
-
}
-
void printI(){
-
cout << "i = " << i << "\n";
-
}
-
};
-
-
class B {
-
char c;
-
public:
-
B() : c('a') {
-
cout << "B's constructor\n";
-
}
-
-
void printC(){
-
cout << "c = " << c << "\n";
-
}
-
};
-
-
class C : public A, public B {
-
public:
-
C() {
-
cout << "C's constructor\n";
-
}
-
};
-
-
int main () {
-
C c;
-
-
c.printI();
-
c.printC();
-
}
$ gcc test.cpp $ a.out A's constructor B's constructor C's constructor i = 1 c = a
Comments
No Comments have been Posted.
Post Comment
Please Login to Post a Comment.