What are the things are inherited from the base class?
What is the output of the program?
#include<iostream>
using namespace std;
class Base
{
protected:
int a;
public:
Base() {a = 0;}
};
class Derived1: public Base
{
public:
int c;
};
class Derived2: public Base
{
public:
int c;
};
class DerivedDerived: public Derived1, public Derived2
{
public:
void show() { cout << a; }
};
int main(void)
{
DerivedDerived d;
d.show();
return 0;
}
1 Crore+ students have signed up on EduRev. Have you? Download the App |
Which symbol is used to create multiple inheritance?
What is the output of the program?
#include<iostream>
using namespace std;
class Base
{
public :
int x, y;
public:
Base(int i, int j){ x = i; y = j; }
};
class Derived : public Base
{
public:
Derived(int i, int j):x(i), y(j) {}
void print() {cout << x <<" "<< y; }
};
int main(void)
{
Derived q(10, 10);
q.print();
return 0;
}
What is the syntax of inheritance of class?
What is the output of the program?
#include<iostream>
using namespace std;
class Base1 {
public:
Base1()
{ cout << " Base1's constructor called" << endl; }
};
class Base2 {
public:
Base2()
{ cout << "Base2's constructor called" << endl; }
};
class Derived: public Base1, public Base2 {
public:
Derived()
{ cout << "Derived's constructor called" << endl; }
};
int main()
{
Derived d;
return 0;
}
When the inheritance is private, the private methods in base class are __________ in the derived class (in C++).
Which of the following advantages we lose by using multiple inheritance?
Assume that an integer takes 4 bytes and there is no alignment in following classes, predict the output.
#include<iostream>
using namespace std;
class base {
int arr[10];
};
class b1: public base { };
class b2: public base { };
class derived: public b1, public b2 {};
int main(void)
{
cout << sizeof(derived);
return 0;
}
What is the output of the program?
#include<iostream>
using namespace std;
class Base {
private:
int i, j;
public:
Base(int _i = 0, int _j = 0): i(_i), j(_j) { }
};
class Derived: public Base {
public:
void show(){
cout<<" i = "<<i<<" j = "<<j;
}
};
int main(void) {
Derived d;
d.show();
return 0;
}
How many constructors can present in a class?
What is the output of the program?
#include<iostream>
using namespace std;
class Base
{
public:
void show()
{
cout<<" In Base ";
}
};
class Derived: public Base
{
public:
int x;
void show()
{
cout<<"In Derived ";
}
Derived()
{
x = 10;
}
};
int main(void)
{
Base *bp, b;
Derived d;
bp = &d;
bp->show();
cout << bp->x;
return 0;
}
What does derived class does not inherit from the base class?