Concept of Multiple Inheritance, required to solve the issues

Asked By 10 points N/A Posted on -
qa-featured

Hi,

Can anyone guide me about the concepts of inheritance and multiple inheritances?

I am waiting for the complete solution.

Please explain in detail.

SHARE
Best Answer by Fahar
Answered By 0 points N/A #91618

Concept of Multiple Inheritance, required to solve the issues

qa-featured

For example you want to create a drawing of an Apple. You can classify Apple as a fruit. Therefore, if you have a class that is, for example, named "Fruit" which describes objects that are "sweet and fleshy product of a tree or other plant that contains seed and can be eaten as food". Then you can inherit the drawing of an Apple in the class Fruit.

But what if you also have another class named "Drawing" which describes objects that are "picture or diagram made with a pencil, pen, or crayon rather than paint"? You can also inherit the object you are creating in class Drawing, right? That is the concept of multiple inheritance.

For more details, you can visit the programming tutorial.

Answered By 10 points N/A #91619

Concept of Multiple Inheritance, required to solve the issues

qa-featured

How can we use the features of parent class, in the child class when we are working with multiple inheritances? And what will happen if we have the same function in both parent classes?

 

Best Answer
Best Answer
Answered By 10 points N/A #91621

Concept of Multiple Inheritance, required to solve the issues

qa-featured

In object oriented programming, one of the most important functionality is about Inheritance in both single and multiple forms.

The basic and simple concept of inheritance is like child and parent. Every child has some face features or some other qualities same like his parents. These qualities are called inherited qualities from parents. Same is the case with inheritance. That is why the base class is called parent class and the inherited class is called child class of parent class.

In case of multiple inheritances, child class has more than one parent classes. For example mermaid is a child class inherited from both Women and Fish classes.

Hope you understand. If you need more information let me know.

Answered By 10 points N/A #91623

Concept of Multiple Inheritance, required to solve the issues

qa-featured

For your help I am sending you a code of a program. Hope it will help you more to understand the concepts.

class Fish
{

protected:
    int x;
public:
Fish( )
{
cout<<endl<<"Fish constructor";
x=1;
}
void display( )
{
cout<<endl<<"Value of x for Fish is : "<<x;
}

};
class Women
{

protected:
    int x;
public:
Women( )
{
cout<<endl<<"Women constructor";
x=100;
}
void display( )
{
cout<<endl<<"Value of x for Women is : "<<x;
}

};
class Mermaid:public Fish, public Women
{

public:
Mermaid( )
{
Fish::x=10;
cout<<endl<<"This is the Mermaid of Fish and Women";
}`
void display( )
{
cout<<endl<<"This is Mermaid display function.";
}

};
int main( )
{

Mermaid m1;
m1.Fish::display( );
m1.display( );
return 0;

}

The output will be:

Fish constructor
Women constructor
This is the Mermaid of Fish and Women
Value of x for Fish is : 10
This is Mermaid display function

Answered By 10 points N/A #91625

Concept of Multiple Inheritance, required to solve the issues

qa-featured

Absolutely right solution for my problem, I have solved it before, according to your tips. But it's awesome to see this coding approach. Very concise and to the point. Thanks a lot.

Related Questions