Multiple inheritance in C++ programming is a feature of OOP. In which an object or class can inherit characteristics and features from more than one parent object or parent class.
Multiple inheritance is a feature of some object-oriented computer programming
languages in which an object or class can inherit characteristics and features
from more than one parent object or parent class. It is distinct from single
inheritance, where an object or class may only inherit from one particular
object or class.
Multiple inheritance has been a sensitive issue for many years, with opponents
pointing to its increased complexity and ambiguity in situations such as the
diamond problem
, where it may be ambiguous as to which parent class a
particular feature is inherited from if more than one parent class implements
said feature. This can be addressed in various ways, including using virtual
inheritance. Alternate methods of object composition not based on inheritance
such as mixins and traits have also been proposed to address the ambiguity.
#include<iostream.h>
#include<conio.h>
class cls
{
public:
void fun()
{
cout<<"This is fun() function of class cls"<<endl;
}
void fun2(char c)
{
cout<<"Iam in Section "<<c<<endl;
}
};
class cls2:public cls //inheriting class 'cls2' from class 'cls'.
{
public:
cls2()
{
cout<<"This is Default Constructor of class cls2"<<endl;
}
};
class cls3:public cls //inheriting class 'cls3' from class 'cls'.
{
public:
cls3() //this is default constructor.
{
cout<<"This is Default Constructor of class cls3"<<endl;
}
};
void main()
{
cls3 ob; //'ob' is object of class 'cls3'.
ob.fun2('A'); //calling function and passing argument.
ob.fun(); //calling 'fun()' function.
cls2 obj; //'obj' is object of class 'cls2'.
obj.fun2('B'); //calling function and passing argument.
obj.fun(); //calling 'fun()' function.
getch();
}