C++ Programming - Constructors and Destructors
Exercise : Constructors and Destructors - Programs
- Constructors and Destructors - General Questions
- Constructors and Destructors - Programs
6.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiaBix
{
int *p;
public:
IndiaBix(int xx, char ch)
{
p = new int();
*p = xx + int(ch);
cout<< *p;
}
~IndiaBix()
{
delete p;
}
};
int main()
{
IndiaBix objBix(10, 'B');
return 0;
}
7.
Which of the following constructor is used in the program given below?
#include<iostream.h>
class IndiaBix
{
int x, y;
public:
IndiaBix(int xx = 10, int yy = 20 )
{
x = xx;
y = yy;
}
void Display()
{
cout<< x << " " << y << endl;
}
~IndiaBix()
{ }
};
int main()
{
IndiaBix objBix;
objBix.Display();
return 0;
}
8.
What will be the output of the following program?
#include<iostream.h>
class BixBase
{
public:
BixBase()
{
cout<< "Base OK. ";
}
};
class BixDerived: public BixBase
{
public:
BixDerived()
{
cout<< "Derived OK. ";
}
~BixDerived()
{
cout<< "Derived DEL. ";
}
};
int main()
{
BixBase objB;
BixDerived objD;
objD.~BixDerived();
return 0;
}
9.
What will be the output of the following program?
#include<iostream.h>
class IndiaBix
{
int x, y;
public:
IndiaBix(int xx)
{
x = ++xx;
}
~IndiaBix()
{
cout<< x - 1 << " ";
}
void Display()
{
cout<< --x + 1 << " ";
}
};
int main()
{
IndiaBix objBix(5);
objBix.Display();
int *p = (int*) &objBix;
*p = 40;
objBix.Display();
return 0;
}
10.
What is the technical word for the function ~IndiaBix() defined in the following program?
#include<iostream.h>
class IndiaBix
{
int x, y;
public:
IndiaBix(int xx = 10, int yy = 20 )
{
x = xx;
y = yy;
}
void Display()
{
cout<< x << " " << y << endl;
}
~IndiaBix()
{ }
};
int main()
{
IndiaBix objBix;
objBix.Display();
return 0;
}
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers