In: Computer Science
Fill in the blanks with suitable code and identify the
type of inheritance in the following code
snippet.(CO5) [Write all the three constructors completely in the
answer sheet. Don’t write any
other parts of the program]
class Xyz
{
int one, two;
public:
Xyz(--------)
{one=i;
--------;
}
};
class Abc
{
int dc;
public:
Abc(int k)
{-----------;}
};
class Ijk: public Abc, public Xyz
{
int f;
public:
Ijk(int l, int m, int z, int n):-------,---------
{ f=n;}
};
int main()
{ Ijk T1(2,6,3,8); }
Class ABC()
{
public:
int a;
ABC()
{
a=1;
}
}
Class XYZ()
{
public:
int b;
ABC()
{
b=2;
}
}
Class pqr(): public ABC, public XYZ
{
public:
int c;
pqr()
{
c=0
c=a+b;
}
}
This type of inheritance is called multiple inheritances. The
class inherits from more than one class. We should call
constructors in the same order in which they are created.
Constructors are called automatically when the object is
created.
There are three constructors in the question ABC, XYZ, and a child
class pqr.
For accessing the constructor of the parent class using the scope
resolution operator(':').
#include<bits/stdc++.h>
using namespace std;
class Xyz
{
int one, two;
public:
//creating parametrized constructor
Xyz(int i, int j)
{
one = i;
two = j;
}
};
class Abc
{
int dc;
public:
Abc(int k)
{
dc = k;
}
};
class Ijk: public Abc, public Xyz
{
int f;
public:
Ijk(int l, int m, int z, int n): Xyz(l, m), Abc(z)
{
f = n;
}
};
int main()
{
Ijk T1(2,6,3,8);
}