A ……………. takes a reference to an object of the same class as itself as an argument.
Destructor is a member function whose name is same as the class name but is preceded by a ……….....
A destructor is used to destroy the objects that have been created by a ………………..
The process of initializing through a copy constructor is known as ……………
………………….. with a constructor (or destructor) cannot be used as a member of a union.
Which of the following statements are not true about destructor?
1. It is invoked when object goes out of the scope
2. Like constructor, it can also have parameters
3. It can be virtual
4. It should always be declared in private section
5. It bears same name as that of the class preceded by Lambda sign.
Which of the following are true about constructors?
1. A class can have more than one constructor.
2. They can be inherited.
3. Their address can be referred.
4. Constructors can be declared in protected section of the class.
5. Constructors cannot return values.
If default constructor is not defined, then how the objects of the class will be created?
Assume class TEST. Which of the following statements is/are responsible to invoke copy constructor?
What will be the output of the following C++ 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;
}
What will be the output of the following C++ program?
#include <iostream>
using namespace std;
class Base1 {
public:
~Base1() { cout << "Base1's destructor" << endl; }
};
class Base2 {
public:
~Base2() { cout << "Base2's destructor" << endl; }
};
class Derived: public Base1, public Base2 {
public:
~Derived() { cout << "Derived's destructor" << endl; }
};
int main()
{
Derived d;
return 0;
}
What will be the output of the following C++ code?
#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;
}
What will be the output of this C++ code?
#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;
}
Consider the below C++ program.
#include<iostream>
using namespace std;
class A
{
public:
A(){ cout <<"1";}
A(const A &obj){ cout <<"2";}
};
class B: virtual A
{
public:
B(){cout <<"3";}
B(const B & obj){cout<<"4";}
};
class C: virtual A
{
public:
C(){cout<<"5";}
C(const C & obj){cout <<"6";}
};
class D:B,C
{
public:
D(){cout<<"7";}
D(const D & obj){cout <<"8";}
};
int main()
{
D d1;
D d(d1);
}
Which of the below is not printed?
In case of inheritance where both base and derived class are having constructors, when an object of derived class is created then ___________ .