Constructors in multiple inheritance in C++ programming. In which an object or class can inherit characteristics and features from more than one parent object or parent class.
#include<iostream.h>
#include<conio.h>
class cls
{
public:
void fun()
{
cout<<"This is fun() function of class cls"<<endl;
}
};
class cls2
{
public:
void fun2()
{
cout<<"This is fun2() function of class cls2"<<endl;
}
};
class cls3
{
public:
void fun3()
{
cout<<"This is fun3() function of class cls3"<<endl;
}
}; //class 'cls4' inheriting from class 'cls2, cls3 and cls'.
class cls4: public cls2, public cls3, public cls
{
public:
void fun4()
{
cout<<"This is fun4() function fo class cls4"<<endl;
fun2(); //calling 'fun2()' function.
fun(); //calling 'fun()' function.
fun3(); //calling 'fun3()' function.
}
};
class cls5: public cls4 //class 'cls5' inheriting from class 'cls4'.
{
public:
void fun5()
{
cout<<"This is fun5() function of class cls5"<<endl;
fun4(); //calling 'fun4()' function.
}
};
void main()
{
cls5 obj; //'obj' is object of class 'cls5'.
obj.fun5(); //and calling 'fun5()' function.
getch();
}
#include<iostream.h>
#include<conio.h>
class cls
{
public:
cls()
{
cout<<"This is Default Constructor of Class cls"<<endl;
}
};
class cls2
{
public:
cls2()
{
cout<<"This is Default Constructor of Class cls2"<<endl;
}
};
class cls3
{
public:
cls3()
{
cout<<"This is Default Constructor of Class cls3"<<endl;
}
}; //class 'cls4' inheriting from class 'cls2, cls3 and cls'.
class cls4: public cls2, public cls3, public cls
{
public:
cls4()
{
cout<<"This is Default Constructor of Class cls4"<<endl;
}
}; //class 'cls5' inheriting from class 'cls4'.
class cls5: public cls4
{
public:
cls5()
{
cout<<"This is Default Constructor of Class cls5"<<endl;
}
};
void main()
{
cls5 obj; //'obj' is object of class 'cls5', and automatic
getch(); //calling all classes Default Constructors.
}